Jump to content

Adding a trailing slash


Krakatoa

Recommended Posts

In my website I have all the links are relative and look like var1/ or var1/var2/

 

I want to redirect them to index.php?p=var1 or index.php?p=var1/var2 without changing the address in the address bar. So I did this:

 

RewriteEngine on

RewriteRule ^(.+)/$ index.php?p=$1 [QSA,L]

 

and it works fine.

But I'd also like to send relative links like var1 and var1/var2 to the same index.php?p=var1 and index.php?p=var1/var2, so I modified the .htaccess like this:

 

RewriteEngine on

RewriteCond %{SCRIPT_FILENAME}!^index\.php$

RewriteCond %{SCRIPT_FILENAME}!^.+/$

RewriteRule ^(.+)$ $1/ [are=301]

RewriteRule ^(.+)/$ index.php?p=$1 [QSA,L]

 

obviously it doesn't work as I hoped... but why? :(

 

Thanks!

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.