Cutting down on mod_rewrite rules
I have two rewrite rules in place: one for hosting server and one for my local test server (which uses 开发者_高级运维dev-sk-... for its URLs).
'en/' is added if the site is accessed via a .co.uk domain name:
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{SERVER_PORT} 443
RewriteCond %{HTTP_HOST} ^domain.co.uk$ [NC]
RewriteRule ^$ http://domain.co.uk/en/ [R=301,L]
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{SERVER_PORT} 443
RewriteCond %{HTTP_HOST} ^dev-sk-domain.co.uk$ [NC]
RewriteRule ^$ http://dev-sk-domain.co.uk/en/ [R=301,L]
Can these be merged into one rule?
you should be able to write this as
RewriteCond %{SERVER_PORT} 80 [OR]
RewriteCond %{SERVER_PORT} 443
RewriteCond %{HTTP_HOST} domain.co.uk$ [NC]
RewriteRule ^$ http://%{HTTP_HOST}/en/ [R=301,L]
精彩评论