htaccess start of URL edits

FORCE WWW RewriteEngine on RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC] FORCE WWW GENERIC WAY RewriteCond %{HTTP_HOST} !^$ RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTPS}s ^on(s)| RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] FORCE NON-WWW RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.example\.com [NC] RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] FORCE NON-WWW GENERIC WAY RewriteEngine on RewriteCond %{HTTP_HOST} ^www\. RewriteCond %{HTTPS}s ^on(s)|off RewriteCond http%1://%{HTTP_HOST} ^(https?://)(www\.)?(.+)$ RewriteRule ^ %1%3%{REQUEST_URI} [R=301,L]
I've added more then one way as sometimes it may not work for all server setups, so you might need to try the other one :) Enjoy

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.