开发者

Having problems adding '/' to end of URI

开发者 https://www.devze.com 2023-02-17 21:19 出处:网络
Right now i have a url which is like http://www.example.com/customer/login i want the URI to always have a ending trail because ill use redire开发者_JAVA技巧cts with ../

Right now i have a url which is like

http://www.example.com/customer/login

i want the URI to always have a ending trail because ill use redire开发者_JAVA技巧cts with ../ and if it doesnt have slash it messes everything up if it has a slash it works fine. I tried to look at some examples online but i couldnt really get anything to work heres my current .htaccess file

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?rt=$1 [QSA] 


Anubhava's got the basic answer and I modded him up. You need to send an HTTP redirect to get the browser to request the URL with the / at the end.

To merge with your existing rewrite rules, you should do:

RewriteEngine on

# First check it's not a file
RewriteCond %{REQUEST_FILENAME} !-f
# And it doesn't end in /
RewriteCond %{REQUEST_URI} !.*/$
# Send the redirect. I would do 301 (permanent) here
# the "L" means the rest of the rules are ignored for this request
RewriteRule ^(.*)$ $1/ [L,R=301]

# Now pass thru to your old ruleset URLs the slash-checker didn't catch
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?rt=$1 [QSA]


How about this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=302]


Try using following rules

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?rt=$1 [QSA] 

#following rule checks if url is not ending with / and
#if not then redirected to url which is ending with /
RewriteCond %{REQUEST_URI} !.*/$
RewriteRule ^(.*)$  $1/ [R=302,L]
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号