开发者

universal .htaccess to write

I am using .htaccess for all my websites.

I would to make a universal .htaccess file to re-write to www.

for each and every domain address I have to replace on the .htaccess file

is there any trick开发者_如何转开发s to get a universal which is change based on hosted server name with HTTP_HOST name


How about:

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,QSA]

UPD: got this rule worked locally


Add this into your httpd.conf or apache.conf, whichever you use:

RewriteEngine On

RewriteCond %{HTTP_HOST}   !^www\.          [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{HTTP_HOST}   (.+)$
RewriteRule ^(.*)          http://www.%1/$1 [L,R=301]

RewriteCond %{HTTPS}       on                [NC]
RewriteCond %{HTTP_HOST}   !^www\.           [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{HTTP_HOST}   (.+)$
RewriteRule ^(.*)          https://www.%1/$1 [L,R=301]

Works for HTTPS and default hosts too.


You could stuff your rewrite rules in the httpd.conf, then it'll work for all sites.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜