我有一个wordpress博客,我们已经有了下面的htaccess代码。
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
</IfModule>
# END WordPress
现在我想添加另一个规则来从特定的URL中删除。php扩展名。
说。我们有abc.com/def/ghi.php
我想要一个规则来忽略这个特定url的.php扩展名。我尝试了以下,但它不起作用。
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
RewriteRule ^(def)/(ghi)/?$ /$1.php [L,NC]
</IfModule>
# END WordPress
我错过了什么吗?
您需要更正.php
添加规则的正则表达式,并将其保留在WP的前端控制器规则之前:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index'.php$ - [L]
RewriteRule ^(def|ghi)/?$ $1.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
</IfModule>
# END WordPress