What's wrong with this mod_rewrite statement?

Deadly 提交于 2020-01-25 22:18:38

问题


I need to replicate the functionality of mod_alias which I can't use directly because I'm on shared hosting, and Alias statements don't work in .htaccess.

What I want to achieve is essentially

Alias /manual /www/customer/some_other_dir/manual

I am trying mod_rewrite:

RewriteRule ^/manual/(.*) /www/customer/some_other_dir/manual/%1?%{QUERY_STRING} [L]

this will never match any calls to www.example.com/manual.

Why not? What am I doing wrong?


回答1:


Try:

RewriteRule ^/manual(/(.*))?$ /www/customer/some_other_dir/$2 [L]

The ? means optional for the / character in addition to the kleene closure on the . to ensure /manual, /manual/ and /manual/a/b/c although I gather a slash is usually added by apache pre-rewrite engine anyway.

A quick test on my box shows this rule also passes the query string:

/manual/a/b?c=d -> /www/customer/some_other_dir/manual/$2



回答2:


Tun off Multiviews option

Options -Multiviews

and i think, it's expect / at end of requested URL.

Something like this will match www.example.com/manual too.

RewriteRule ^/manual/?(.*) /www/customer/some_other_dir/manual/%1?%{QUERY_STRING} [L]


来源:https://stackoverflow.com/questions/2188274/whats-wrong-with-this-mod-rewrite-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!