How to get global mod_rewrite rules working? (w/o htaccess!)

Problems with the Windows version of XAMPP, questions, comments, and anything related.

How to get global mod_rewrite rules working? (w/o htaccess!)

Postby QuestionOverflow » 15. October 2012 13:42

For some reason, every single tutorial/answer I find on creating mod_rewrite rules in Apache (or XAMPP, more specifically) only covers the use of .htaccess files, but I need to create "global" mod_rewrite rules, i.e. what is called "on the VirtualHost level" in the Apache docs.

I have enabled/uncommented the loading of the mod_rewrite module in the httpd.conf file, and as far as I understand it, all that should need to be done after that is to add the following lines at the right location in the Apache config:

Code: Select all
RewriteEngine on
RewriteRule ^/?testtest/.* /test.php

(i.e. this test rule should rewrite all accesses to the URLs "http://localhost/testtest/*" to the URL "http://localhost/test.php")

I have also tried the "L" flag to rule out any strange other rewrites happening after my rewrite, as follows, but with no different results:

Code: Select all
RewriteEngine on
RewriteRule ^/?testtest/.* /test.php [L]

The key words here I guess are "at the right location", because I have tried to insert those lines more or less everywhere, inside individual "Directory" directives and in the last lines of the httpd.conf file, but nothing seems to work? (yes, I restart Apache after each configuration change too)

I don't have any VirtualHost directives defined anywhere in the config except the default "VirtualHost default:443" in "httpd-ssl.conf" (i.e. neither in "httpd.conf" nor "httpd-vhosts.conf"), since I only run a single instance and want these rules to apply everywhere.

So, to summarize it: In a default XAMPP installation (on Windows, if it matters), what is the minimal steps to get a global mod_rewrite rule working, e.g. the test rule listed above (and WITHOUT using any .htaccess files, as explained above)?
QuestionOverflow
 
Posts: 2
Joined: 15. October 2012 13:34
XAMPP Version: 1.8.3-2
Operating System: Windows XP Professional

Re: How to get global mod_rewrite rules working? (w/o htacce

Postby JonB » 15. October 2012 17:28

The 'basic general answer' - almost everything that can be stuffed in .htaccess may also be used in Apache 'Directory' directives that are stored in .conf files.

read these:

http://httpd.apache.org/docs/2.4/configuring.html

http://httpd.apache.org/docs/2.4/howto/htaccess.html

http://httpd.apache.org/docs/2.4/rewrite/

The reason you see little of this instruction/idea on the web is that most folks on shared hosts generally don't have access to the Apache .conf files. Only those who host themselves, or have VPS's or dedicated servers usually have that access.

Edited: you may want to set up a Vhost to test on (that way you can still work without breaking everything) , and then migrate that to the primary 'server'.

Good Luck
8)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
XAMPP Version: 1.8.3-2
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: How to get global mod_rewrite rules working? (w/o htacce

Postby QuestionOverflow » 15. October 2012 20:22

Thanks a lot for your reply. I still can't get it to work though (as mentioned above, I've already tried to stuff the rules inside every 'Directory' directive I can find, without any luck). :(

Maybe I must nuke this XAMPP installation and try in a new one if no progress can be made from here...

Thanks again anyway.
QuestionOverflow
 
Posts: 2
Joined: 15. October 2012 13:34
XAMPP Version: 1.8.3-2
Operating System: Windows XP Professional

Re: How to get global mod_rewrite rules working? (w/o htacce

Postby JonB » 15. October 2012 21:08

Okay then

A. its not a syntax error, tested on a .htaccess tester
B. Also not a XAMPP 1.7.4 error - works on my clean install -

httpd.conf -
Code: Select all
<Directory "C:/xampp-174/htdocs">
     
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks Includes ExecCGI
   
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All
   RewriteEngine on
   RewriteRule ^/?testtest/.* /test.php

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

</Directory>


test.php
Code: Select all
<?php
echo "Hello";
?>


and -
http://localhost/testtest/bob.php

displays my 'Hello' page

Did you put the directives after the AllowOverride All?, and what error are you getting? (just asking)

Good Luck
8)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
XAMPP Version: 1.8.3-2
Operating System: Windows XP/7 - Fedora 15 1.7.7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 36 guests