问题
The offending URLs are:
- (Doesn't work) http://alltheragefaces.com/face/surprised-wut/
- (Works) http://alltheragefaces.com/face/surprised-wut
The .htaccess rule I have for these types of URLs looks like:
RewriteRule ^face/(.*)$ face.php?term=$1
What can I do to make both of these URLs to go to the same page?
回答1:
You can use this:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [L,R=301]
The first line says: "if it's not a directory" (because then a trailing slash would have meaning). The second line says: redirect everything from start to the trailingslash and end to everything that was in there, without the trailing slash.
Put your own RewriteRule in there (below that one, not above) so your normal redirect still works after the trailing slash was removed.
(this one will obviously work for /body/ too, and not only for /face/.
回答2:
I use this rule which is slightly modified to maintain any subfolder structure
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
来源:https://stackoverflow.com/questions/10346944/trailing-slash-causes-404-can-i-fix-using-htaccess