Forum Moderators: phranque

Message Too Old, No Replies

About Rule In .Htaccess

Add Www In The Url

         

lovechina

9:19 am on Jan 29, 2007 (gmt 0)

10+ Year Member



Now , I Want To :

[#*$!.example.com...] the real url is: http://www.example.com/#*$!.html

there should have the 'www'

What Should Write In The .htaccess

here is:

[#*$!.example.com...] to http://www.example.com/folder/#*$!.html

RewriteEngine on
RewriteRule ^\.htaccess$ - [F]
RewriteRule!^www\.
rewritecond %{HTTP_HOST} ^([^.]+)\.example\.com
rewritecond $1!^lk_
RewriteRule (.*) /lk_aaa/%1$1_index\.html

If I Want To Have 'www', How Do?

jdMorgan

5:27 pm on Jan 29, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you want to support the use of "www" with your subdomain rewrite, such as "www.sub.example.com", then this code will accept either "sub.example.com" or "www.sub.example.com":

RewriteEngine on
#
RewriteRule ^\.htaccess$ - [F]

RewriteCond !^www\.example\.com
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.example\.com
RewriteCond $1 !^lk_
RewriteRule (.*) /lk_aaa/%2$1_index\.html


If you want to force all subdomains to start with "www" then that would require an additional rule, added before the rule above:

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

This redirects:
example.com --> www.example.com
sub.example.com --> www.sub.example.com
www.example.com --> No change

Jim