wwfc_barmy_army Posted September 26, 2011 Share Posted September 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/247885-mod_rewrite-confused/ Share on other sites More sharing options...
cags Posted September 26, 2011 Share Posted September 26, 2011 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] Quote Link to comment https://forums.phpfreaks.com/topic/247885-mod_rewrite-confused/#findComment-1272958 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.