Apache重写规则 [英] Apache rewrite rule
问题描述
我想重定向" http://localhost/b.html "->" http://localhost/a.html 我为此尝试了RewriteRule.但是不知何故,它对我不起作用.
I want to redirect "http://localhost/b.html" --> "http://localhost/a.html" I tried RewriteRule for that. But somehow it is not working for me.
我正在使用apache2,我的httpd.conf包含:
I am using apache2 and my httpd.conf contains:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteRule ^/b.html$ http://localhost/a.html
当我输入" http://localhost/a.html 时,它向我显示了该网页.但是当我对" http://localhost/b.html 进行整理时,apache2/error_log表示文件不存在:b.html" 是否缺少任何设置以启用rewrite_module?
When I tri "http://localhost/a.html" It shows me the web page. But when I triend "http://localhost/b.html" apache2/error_log says "file does not exist: b.html" Does any setting missing to enable rewrite_module?
推荐答案
问题出在您的RewriteRule中.这应该工作:
The problem is in your RewriteRule. this should work:
RewriteEngine On
RewriteRule ^/b.html$ /a.html [L]
-
规则匹配项((在.htaccess中有效,但在服务器配置中无效)^b.html$
)不得包含起始斜杠. - 如果可能,重写目标应为相对URI(即在同一主机上)
- 规则应以做什么"的指令结尾-在这种情况下,
[L]
避免处理(不再处理任何规则)
the rule match ((this works in .htaccess, but not in server config)^b.html$
) must not include the starting slash.- the rewrite target should be a relative URI if possible (i.e. on the same host)
- the rule should end with a directive "what to do" - in this case
[L]
eave processing (no more rules will be processed)
这篇关于Apache重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!