Bernie
Bernie

Reputation: 39

rewrite rules not working

I use some rewrite rules inside the Apache virtual hosts configuration httpd-vhosts.conf and it works fine there. Because I want to move to a managed server I have to use the .htaccess file because I don't have access to the apache configuration files.

I tried it locally and somehow I don't get this working at all. Locally I use xampp 1.8.3 (Apache 2.4.10). I put the .htaccess file in the root directory of the virtual host and use this lines for testing

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule /testrule /about/about.php [L]

I always get an 404 error when calling localhost/testrule It works fine when I put it in the httpd-vhosts.conf. mod_rewrite is enabled and I have set AllowOverride All in the Directory part.

Upvotes: 0

Views: 125

Answers (2)

Rahil Wazir
Rahil Wazir

Reputation: 10142

This blog post clearly mention

In VirtualHost context, The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string (e.g. “/app1/index.html”).

In Directory and htaccess context, the Pattern will initially be matched against the filesystem path, after removing the prefix that led the server to the current RewriteRule (e.g. “app1/index.html” or “index.html” depending on where the directives are defined).

So in virtual host context, matches start from /testrule/...

While in .htaccess and <Directory/> context, it matches testrule/...

Upvotes: 1

yunzen
yunzen

Reputation: 33449

You can quick check the htaccess rewrite rules here:
http://htaccess.madewithlove.be/ or here:
http://martinmelin.se/rewrite-rule-tester/

Just get rid of the leading slash in the RewriteRule and you are done

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule testrule /about/about.php [L]

Upvotes: 0

Related Questions