问题
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