【发布时间】:2012-02-02 17:40:28
【问题描述】:
我的 htaccess 文件中有以下内容:
RewriteEngine On
RewriteBase /
# Check to see if the URL points to a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Trailing slash check
RewriteCond %{REQUEST_URI} !(.*)/$
# Add slash if missing & redirect
RewriteRule ^(.*)$ $1/ [L,R=301]
# Check to see if the URL points to a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Send to index.php for clean URLs
RewriteRule ^(.*)$ index.php?/$1 [L]
这确实有效。它隐藏了 index.php,并添加了一个斜杠……除非有查询字符串。
这个网址:
http://example.com/some-page
被重定向到:
http://example.com/some-page/
但是这个网址:
http://example.com/some-page?some-var=foo&some-other-var=bar
不会被重定向。我希望将以上内容发送至:
http://example.com/some-page/?some-var=foo&some-other-var=bar
我已经达到了我对重定向的理解的极限。如果您有一个可行的答案,我将非常感谢每条线路在做什么以及它为什么起作用的演练。解释为什么我现在拥有的在涉及查询字符串时不起作用的双重奖励。
【问题讨论】:
标签: regex apache .htaccess routes pattern-matching