【发布时间】:2017-03-15 07:17:06
【问题描述】:
网站的一页有这样的添加:domain.com/posts/name.php
网站其他页面有这样的补充:domain.com/pages/name.php
我只需要删除这些添加 posts/ 和 pages/。
首先,我尝试在 .htaccess 中使用下一条规则:
RewriteRule ^([A-z0-9-]+)$ /posts/$1
RewriteRule ^([A-z0-9-]+)$ /pages/$1
别帮忙。
其次,我尝试在.htaccess中使用这样的规则和条件:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ posts/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ pages/$1 [L]
结果:image of mistake 404
我也试过用这种方法:
RewriteCond %{REQUEST_URI} ^([A-z0-9-]+)$/(posts|pages)/([A-z0-9-]+)/$1 [NC]
RewriteRule .* domain.com/%1%3
不要帮忙....
【问题讨论】:
-
你不能对多个条件使用相同的情况,你必须对第二条规则使用其他条件。
-
例如? %{REQUEST_URI} 的条件?你能帮忙吗?
标签: php apache .htaccess mod-rewrite url-rewriting