0

这就是我要的 -

当有人进入 site.com/page.php 或 site.com/page 或 site.com/page/ 时,都应该工作相同,地址栏中显示的 url 应该是 site.com/page [ 我不像扩展名和斜杠]

我还想从网址栏中删除 www,因为它是不必要的。

这是我当前的 .htaccess 文件重写规则 -

RewriteEngine on
RewriteCond %{HTTP_HOST} ^site\.com
RewriteRule ^(.*)$ http://www.site.com/$1 [R=permanent,L] 

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

这解决了 www 和扩展名问题,但没有解决斜杠问题!

但是,更重要的是,我最近在 site.com/blog 上安装了 WordPress,但每当我尝试访问它时,我都会被重定向到 404 页面。当我删除所有重写时它会起作用!

我搞砸了我的重写吗?我不是正则表达式忍者!

4

1 回答 1

1

尝试将以下内容添加到现有 .htaccess 文件的顶部,高于任何现有规则,例如 Wordpress 规则。

RewriteEngine on
RewriteBase /

#if the host is not site.com, e.g www.site.com
RewriteCond %{HTTP_HOST} !^site\.com$ [NC]
#then redirect to site.com e.g to remove the www
RewriteRule ^(.*)$ http://site.com/$1 [R=301,L] 

#if the URL ends with a slash
RewriteCond %{REQUEST_URI} ^/(.+)/$
#redirect to URL without slash
RewriteRule . http://site.com/%1 [R=301,L] 

#skip wordpress site which starts with blog
RewriteCond %{REQUEST_URI} !^/blog [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
于 2011-12-15T20:39:12.230 回答