开发者

How to simplify WWW or No WWW in one elegant Apache Rewrite?

开发者 https://www.devze.com 2023-02-21 23:07 出处:网络
Dear folks, The (www.)? part in the below code doesnt work properly I feel: RewriteCond %{HTTP_HOST} ^(www\\.开发者_运维知识库)?mywebsite.com$

Dear folks, The (www.)? part in the below code doesnt work properly I feel:

RewriteCond %{HTTP_HOST} ^(www\.开发者_运维知识库)?mywebsite.com$
RewriteRule ^$ /de/home [L]

The above code now works together with this:

####  http:// >> http://www.
RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

I feel it could be made simpler by extending the first code block sothat it captures both http:// and http://www. towards /de/home

How do adapt the first code block sothat it is versatile and captures any version with or without www to load under water /de/home? Thanks very much


The second set of rule is the way to do it.

%{HTTP_HOST} does not contains http:// part of the URL. Maybe you can use %{THE_REQUEST} but I don't see why use another syntax than the second block.

BTW, how much simpler than "if the host does not match www.-> then add www. to what the user typed" ??

0

精彩评论

暂无评论...
验证码 换一张
取 消