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
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]

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.