Jump to content

Mod_rewrite - Confused..


wwfc_barmy_army

Recommended Posts

Hello.

 

I have this htaccess file:

Options +FollowSymLinks

RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(exe|jpg|jpeg|png)$

RewriteRule ^([^/]*)$ page.php?slug=$1 [L]

 

I accessed localhost/test/test-here...it works ok, but the slug variable is outputting 'page.php'. So I tried this:

RewriteRule ^help/([^/]*)$ page.php?slug=$1 [L]

I accessed localhost/test/help/test-here... and it worked and the slug variable was 'test-here'.

 

The htaccess is in the root of the 'test' folder.

 

Any ideas?

 

Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/247885-mod_rewrite-confused/
Share on other sites

It sounds like you are triggering a redirect rather than a rewrite, which will cause the .htaccess to be parsed a second time. This time through the requrest is for page.php?slug=test-here, but when that hit's the rules you are replacing the slug value with the value of the page which is giving page.php?slug=page.php, not quite sure how that would be happening though as normally this would cause an infinite loop and crash. Perhaps it's hitting some kind of rewrite limit first. Either way, you should be able to stop that happening by adding another RewriteCond checking if the file requested actually exists.

 

Options +FollowSymLinks

RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(exe|jpg|jpeg|png)$
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^([^/]*)$ page.php?slug=$1 [L]

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.