【发布时间】:2013-07-25 16:18:36
【问题描述】:
我将所有传入我网站的 URL 请求都转换为 GET 参数,因此 fruits.com/apple 变为 fruits.com/?url=apple 并且我的路由机制负责显示正确的视图。
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule .* index.php?url=$0 [QSA,L]
这很好用。但是我现在有一些例外,我希望这些 URL 重定向到主页。 Redirect与上述规则冲突:
Redirect /pineapple /
Redirect /grapes /
这会重定向到fruits.com/?url=pineapple 而不仅仅是fruits.com。
如何干净地重定向到fruits.com?
可怕的解决方案
我能想到一种解决方案,除了几个例外之外,它是非常不优雅的:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteCond %{REQUEST_URI} !^/pineapple$
RewriteCond %{REQUEST_URI} !^/grapes$
RewriteRule .* index.php?url=$0 [QSA,L]
Redirect /pineapple /
Redirect /grapes /
【问题讨论】:
标签: apache .htaccess mod-rewrite