我知道这个问题已经被问过很多次了,但是目前为止我还没有看到有什么效果。
我有一个wp在根,从子目录运行(我喜欢的东西干净)。我也从子目录在根运行的几个子域(例如。public_html/sample.com)。我只在纯HTML和CSS的子域上得到错误。他们不使用任何平台。
这是我的。htaccess从根目录
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
我尝试过的事情:
1)注释掉所有rewriterrule -解决了问题,但然后我的wp不工作。当我进入任何帖子或页面时,它给出404错误。
2)将。htaccess更改为以下内容(由Scott Yang提供):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php/$1 [L,QSA]
</IfModule>
但这并没有改变什么。
3)我也试着从其他问题中注释和粘贴新的代码,相当随机,但它是相同的故事。
任何想法?
欢呼
我找到解决办法了。
在子域的根目录中,在。htaccess中添加以下内容:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
Rewrite Rule ^([^.]+)$ $1.php [NC,L]
这是你如何从URL末尾去掉。php的方法。
将。php替换为。html,也会删除。html
由于某些原因,这解决了这个问题。
欢呼编辑:这解决了问题,但它没有从URL中删除。html。
#example.com/page will display the contents of example.com/page.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
#301 from example.com/page.html to example.com/page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}' /.*'.html' HTTP/
RewriteRule ^(.*)'.html$ /$1 [R=301,L]
欢呼