我的mod_rewrite模块存在问题。如果我执行/ toronto /它会相应地指示我,但是,如果我执行/ toronto而没有尾随斜线它会返回404.我需要/ toronto和/ toronto /来从/ city_name文件夹中读取。如何避免使用尾部斜杠,这是我的代码:
RewriteEngine On RewriteBase / city_name
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)/$ /city_name/index.php?page=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /([^\./]+)\.php$
RewriteCond %{DOCUMENT_ROOT}/city_name/%1.php -f
RewriteRule ^(.*)/([^\./]+)\.php$ /city_name/$2.php?page=$1 [L,QSA]
答案 0 :(得分:1)
RewriteRule (.*)/$ /city_name/index.php?page=$1 [L,QSA]
此规则明确指出URI必须以斜杠结尾,因此'toronto'不匹配任何规则。要使斜线可选,请使用?操作者:
RewriteRule (.*)/?$ /city_name/index.php?page=$1 [L,QSA]