0

我的脚本在我的根域中的一个目录中,但总是重定向:

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

1 回答 1

0

也许你可以尝试使用这个:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9\-]+)/$ $1 [R,L]

它在我的网站上运行良好。由于谷歌的搜索结果显示我的网站升级之前的旧结果。很多搜索结果显示

homepage.com/property/

/但是对于新网站(CMS),如果在最后一个页面上,则无法访问属性页面

因此,有了我.htaccess的代码,它就像魔术一样工作。即使来自谷歌的搜索结果/在地址的末尾

于 2013-07-15T14:30:31.620 回答