【发布时间】:2014-02-11 01:37:32
【问题描述】:
我有执行 URL 重写的 htaccess 文件。它基本上删除了 .php 扩展名。
规则工作正常,例如他们成功地将http://example.com/contact.php 改写为http://example.com/contact
但是重写也会更改子目录文件,例如/includes/check-form-input.php。
因此,例如,当contact.php 的表单尝试提交到/includes/check-form-input.php 时,htaccess 重写会从末尾剥离 .php,我得到 404 个标题。
即/includes/check-form-input 未找到。
至少看起来是这样,使用HTTP_REFERER 似乎证实了这一点,因为引用者是/includes/check-form-input 没有分机.php
有没有办法添加一个规则来否定所有子目录?
我有以下 htaccess - 这是从 SO 上的另一个答案复制而来的,因为我没有 100% 掌握重写结构。
(如果这是原因,我已经离开 www 到非 www 重定向)
## Rewrite on
RewriteEngine on
## Redirect all pages from non-www to www
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
## URL rewrite
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
【问题讨论】:
标签: .htaccess mod-rewrite url-rewriting