Adding 'www' to url via .htacess mod_rewrite does not work - .htaccess

Here is the sample found in numerous posts
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yatko.com[NC]
RewriteRule ^(.*)$ http://www.yatko.com/$1 [R=301,L]
*wanted to rewrite the main domain only leaving the addon/parked domains unaffected
- the sample above does not work for some reason.

updated
did you set RewriteEngine On on top of the .htaccess ? :
RewriteEngine On
RewriteCond %{HTTP_HOST} !^yatko\.com [NC]
RewriteRule ^(.*)$ http://www.yatko.com/$1 [R=301,L]

Related

Redirect 2 directories to a particular URL

I already have this written in my .htaccess file.
Redirects all traffic to my newsite.co.uk except for oldsite.net/dlg and oldsite.net/members
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/dlg(/?$|/.*$) [NC]
RewriteCond %{REQUEST_URI} !^/members(/?$|/.*$) [NC]
RewriteCond %{HTTP_HOST} !^.*newsite.co.uk.*$ [NC]
RewriteRule ^(.*)$ http://www.newsite.co.uk/$1 [R=301,L]
However my e-commerce pages at oldsite.net/dlg and oldsite.net/members are currently down. So until these pages are back up, is it possible to rewrite the above code, to remove the exception but make /dlg and/members divert to a particular page on my newsite.co.uk?
Thanks in advance!
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newsite.co.uk// [R=301,L]
for further information
http://www.webconfs.com/how-to-redirect-a-webpage.php

Multiple htaccess redirects at once

I'm having some issues with redirecting a clients website.
I have a site with a /uk directory that's being redirected to a uk sub-domain, Everything else redirects to a new URL
This all works fine, but they now need to access the old sites /uk/administrator directory. How can I exclude /uk/administrator from the other rules?
Here is my current set-up:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example.com\.com$
RewriteRule ^uk/(.*) http://uk.example.com/$1 [R=301,L]
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ http://www.newexample.com/ [R=301,L]
I've been frantically Googeling for the past 30min with no luck.
Try :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example.com\.com$
#Exclude /uk/administ
RewriteCond %{REQUEST_URI} !^/uk/administrator/
RewriteRule ^uk/(.*) http://uk.example.com/$1 [R=301,L]
You can use negative lookahead:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example.com\.com$ [NC]
RewriteRule ^uk/((?!administrator/).*)$ http://uk.example.com/$1 [R=301,L]
RewriteRule ^(.*)$ http://www.newexample.com/$1 [R=301,L]

.htaccess RewriteRule subsubdomain.subdomain.domain.tld to subdomain.domain.tld/subsubdomain

Is it posible to redirect a sub-subdomain into a subdomain with the sub-sub domain as new folder using .htaccess rewrite-rule?
For example... When i go to 2013.archive.example.com I want to end up in archive.example.com/2013..
Already tried some things, current .htaccess is:
RewriteRule On
RewriteCond %{HTTP_HOST} ^(.*)\.archive\.example\.com$
RewriteRule ^(.*)$ archive.example.com/%1/$1 [L]
Unfortunately it isn't working. Any suggestions for this?
Changed it a but, currently using:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.archive\.example\.com$ [NC]
RewriteRule ^(.*)$ %1/$1 [L]
and is working exactly how I wanted:)
For external redirect: (URL change in browser)
You can use this rule in your DOCUMENT_ROOT/.htaccess:
RewriteCond %{HTTP_HOST} ^([^.]+)\.(archive\.example\.com)$ [NC]
RewriteRule ^ http://%2/%1%{REQUEST_URI} [L,R=301]
This will work provided DOCUMENT_ROOT is same for anything.archive.example.com and archive.example.com.
For internal forward: (No URL change in browser)
You can use this rule in your DOCUMENT_ROOT/.htaccess:
RewriteCond %{HTTP_HOST} ^([^.]+)\.archive\.example\.com$ [NC]
RewriteRule ^ /%1%{REQUEST_URI} [L]
If they share the same root, then you don't need the archive.example.com part in your rule's target:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.archive\.example\.com$ [NC]
RewriteRule ^(.*)$ /%1/$1 [L]

Non WWW to WWW redirection using htaccess File

I am using Codeigniter-.
My domain currently does not redirect to www version.
For example if I type mydomain.com then it stays mydomain.com. I want to redirect it to www.mydomain.com.
If someone types mydomain.com/controller/method then it should be www.mydomain.com/controller/method.
Another problem: I already tried other solutions but the problem is when it redirects to www version, it automatically adds "index.php" in the URL. But when I type www in the domain name then it works fine, no "index.php" in the URL. This problem occurs only during the redirection.
Here is my .htaccess file (I've removed the redirection code)
RewriteCond $1 !^(index\.php|system|rpc_relay.html|canvas.html|robots\.txt)
RewriteCond $1 !^(sitemap\.xml|export)
RewriteRule ^(.*)$ /index.php/$1 [L]
Any help would be greatly appreciated.
To redirect from http:// to http://www. , and also remove the route file (index.php) in the url, put these lines on your htaccess :
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteCond $1 !^(index\.php|images|css|js|styles|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
the domain is :
domain.com
folder with direct access :
images|css|js|styles
hope this help
I've used the following before:
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteCond %{HTTP_HOST} (.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
</IfModule>
To redirect domain.com to www.domain.com, you could use the following rewrite rule. Please replace domain.com with your own domain name.
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
I don't know why there are such complex RewriteRules answers, even though Gobhi has provided a nice generic solution (= whatever the domain name is, it works).
Here's my solution.
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
RewriteRule (.*)/index\.php$ $1/ [QSA]
</IfModule>

how to modify .htaccess file to always redirect to www

I would like to modify my .htaccess file so that when someone comes into my site without typing www the site always redirects them to the www version. For example, if my url is www.abc.com and they just type abc.com, I want to redirect them to abc.com.
Here is my current htaccess file:
<IfModule mod_rewrite.c>
RewriteBase /
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Normally I know how to do the redirect, but im having issues since it already has those few lines in there.
I use the code below. It can be used for any domain name. You just need to enter it in your .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
(edited to have all the code in the same block)
Add something like this immediately after RewriteEngine on:
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) http://www.example.com/$1 [R=301]
There are two methods available
1) use mod_alias apache module
Redirect permanent /something http://yourwebsite.com/something
2) Add the following entry in your .htaccess / http.conf / yourwebsite.conf in the webserver configuarion directory
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourwebsite.com
RewriteRule ^(.*)$ http://www.yourwebsite.com$1 [R=permanent,L]
If you want redirect example.com to www.example.com you can try below code
RewriteEngine on
RewriteCond %{HTTP_HOST} !www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

Resources