我的脚本在我的根域中的一个目录中,但总是重定向:
http://www.mydomain.com/script
至
http://www.mydomain.com/script/
而且我想仅在 index.php (主页)中删除尾部斜杠以删除该重定向,并且如果我输入没有尾部斜杠的 URL 正确重定向到
http://www.mydomain.com/script
我的 HTACCESS 代码是:
Options +FollowSymLinks
Options -Indexes
ServerSignature Off
RewriteEngine on
# Force NON WWW TO WWW in all pages.
RewriteBase /script
RewriteCond %{THE_REQUEST} ^.*\/index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
RewriteCond %{http_host} ^mydomain.com$ [nc]
RewriteRule ^(.*)$ http://www.mydomain.com/script/$1 [r=301,nc,L]
# Remove the .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
# Force the trailing slash at the end of urls
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
# SEO URLs
RewriteRule ^post/([^/\.]+)/?$ post.php?id=$1 [L]