我已经建立了一个Wordpress网站。 我需要递归删除特定文件夹中文件的.php扩展名。递归删除.php .htaccess和Wordpress
说: www.domain.com/wordpresspage/(设置与永久链接,都很好)。
然后我需要递归删除.PHP的文件夹: domain.com/gz/*
domain.com/gz/的内容应该有PHP扩展删除。但仅限于此文件夹。
文件夹结构
/
-/images (No .htaccess rules should apply, Wordpress takes care of it.)
-/downloads (No .htaccess rules should apply, Wordpress takes care of it.)
-/gz (.htaccess change, to remove .php file extension, overwriting Wordpress, in this particular folder)
-file1 (No .htaccess rules should apply, Wordpress takes care of it.)
-file2 (No .htaccess rules should apply, Wordpress takes care of it.)
之前我用下面的.htaccess内容删除扩展名为.php,但现在我只需要迫使这对一个文件夹,因为WordPress的,走的是剩下的事情。
#RewriteBase/
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.php\ HTTP
#RewriteRule ^([^.]+)\.php$ https://example.com/$1 [R=301,L]
#RewriteCond %{REQUEST_URI} !(\.[^./]+)$
#RewriteCond %{REQUEST_fileNAME} !-d
#RewriteCond %{REQUEST_fileNAME} !-f
#RewriteRule (.*) $1.php [L]
我试过一吨的事情了,但过去几年包括:
- 使用旧的.htaccess文件,消除.PHP上的所有网页。这解决了我的路径问题,但在网站的其他部分发生内部服务器错误。
- 试图通过递归过滤出该文件夹的巨大方法,直到我不再确定它是否可能。 (甚至不记得我试过的一小部分)。
- 尝试在永久链接添加.php - 但由于它将重定向以再次删除它,我会得到另一个内部服务器错误。
TL; DR - 我可以在我的.htaccess文件的特定路径上递归移除.php文件,所以WordPress会忽略这个文件夹并让它处理它自己的业务?
新增首轮帮助后,我的.htaccess文件现在看起来像这样:
# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
RewriteEngine On
# Only apply if request starts with /gz/
# followed by at least one character and ends with .php
RewriteCond %{REQUEST_URI} ^/?gz/[^.]+\.php$
# Redirect to the same location but without .php ant the end
RewriteRule ^/?(.*)\.php$ /$1 [R=301,L]
# Only apply if request starts with /gz/ followed by at least one character
RewriteCond %{REQUEST_URI} ^/?gz/[^.]+$
# and the request it not a real directory
RewriteCond %{REQUEST_FILENAME} !-d
# and the request it not a real file
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite the request with .php at the end
RewriteRule ^(.*)$ /$1.php [L]
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AddType application/x-httpd-php-old .php
<IfModule security_module>
SecFilterEngine Off
</IfModule>
<IfModule security2_module>
SecRuleRemoveByID 1-99999
SecRuleRemoveByTag unoeuro
</IfModule>
后重新申请固定链接,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 [L]
</IfModule>
# END WordPress
由于提前,
大号