How to get global mod_rewrite rules working? (w/o htaccess!)
Posted: 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:
(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:
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)?
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)?