页面显示错误页面而不是预期页面

时间:2013-05-03 20:35:33

标签: apache url mod-rewrite rewrite

这段代码让我感到困惑的是为什么会这样。如果我添加[R = 302,L] 然后我的链接完全正如我希望的那样。但如果我不添加它,我只有[L] 它会进入错误页面。 R和否R之间的区别不在于浏览器中的地址栏是否更新?

这是代码中的最后一行。我正在尝试做一个内部/无声的mod_rewrite

我想要用户输入http://example.comhttp://example.com/home/

我想在内部使用相同的网址http://example.com/home

# Do not remove this line, otherwise mod_rewrite rules will stop working

RewriteBase /

AddHandler application/x-httpd-php .css

AddHandler application/x-httpd-php .js
Options +Multiviews

RewriteEngine On

#NC not case sensitive
#L last rule don't process futher
#R 301 changes the url to what you want


#changes the host to make sure it has no www infront
RewriteCond %{HTTP_HOST} !^example\.host56\.com 
RewriteRule ^(.*)$ http://example.host56.com [R=302,L]


#kills request with file extensions
RewriteCond %{THE_REQUEST} \.(php|jsp|html|jsp|asp)/?\ HTTP/
RewriteRule .* - [F]

#selects home
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\ HTTP/1.1$
RewriteRule ^.*$ home/ [L]

1 个答案:

答案 0 :(得分:0)

通过传递R=***标志,您强制浏览器在新URL处实际针对服务器发出新请求。在随后的请求中,由于主机名已经是你想要的,这显然会在下一个请求中跳过这个条件并继续使用其余的htaccess逻辑。

如果删除此选项并仅保留L标记。您指出这是您应该处理的htaccess中的最新规则,因此文件中的以下规则将永远不会被执行(我猜这会导致错误页面出现)。

相关问题