Work fine but redirect www.site.com/robots.txt to site.com/robots.txt
I try to avoid robots.txt redirect. What need to add?
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !robots\.txt
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Related
Ok, so i want to redirect all www to non www link,
I want to redirect www.example.com to example.com, and i can do that too using this code.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
But when someone try to access www.example.com/example, that redirects the site to example.com,
I want a code that can redirect www.example.com/example or any subfolder to example.com/example or any subfolder.
Kinda like a wildcard entry, how to do that?
Also if possible force ssl on it too.
Thank You.
If I've understood your question correctly:
www.example.com/dir/anypage.html to example.com/dir/anypage.html (same page)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [nocase]
RewriteRule ^(.*) http://example.com/$1 [last,redirect=301]
OR Use:
RewriteCond %{HTTP_HOST} ^(www\.example\.com)?$
RewriteRule ^(.*)$ http://example.com/subfoldername/$1 [R=301,L]
-------- Alternative---------
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(example\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1 [L]
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(/)?$ /subfolder/index.php [L]
To force SSL:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
hope some could help me.
I have a wordpress blog with 3 domains, .com, .es and .net. The .com is the target.
And i want to redirect from non-www to www as well.
The redirect from .es to .com works fine, and .net to .com too. But when i add the redirect from non-www to www is not working and the site doesnt load.
This is my .htaccess file...
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^myblog.com [NC]
RewriteRule ^(.*)$ http://www.myblog.com/$1 [L,R=301,NC]
#RewriteCond %{HTTP_HOST} ^myblog.es$ [OR]
#RewriteCond %{HTTP_HOST} ^www.myblog.es$
#RewriteRule ^(.*)$ "http\:\/\/www\.myblog\.com/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^myblog\.es$ [OR]
RewriteCond %{HTTP_HOST} ^www\.myblog\.es$
RewriteRule ^(.*)$ "http\:\/\/myblog\.com\/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^myblog.net [NC,OR]
RewriteCond %{HTTP_HOST} ^www.myblog.net [NC]
RewriteRule ^(.*)$ http://www.myblog.com/$1 [L,R=301,NC]
These rules should suffice for your needs:
RewriteEngine On
# redirect myblog.es and myblog.net (with or without www.) to www.myblog.com
RewriteCond %{HTTP_HOST} ^(www\.)?myblog\.(es|net)$
RewriteRule ^(.*)$ http://www.myblog.com/$1 [R=301,L]
# Force www on myblog.com
RewriteCond %{HTTP_HOST} ^myblog.com [NC]
RewriteRule ^(.*)$ http://www.myblog.com/$1 [L,R=301,NC]
I used to have a website at www.roboticsguy.com, which I moved over to www.foxytronics.com. I want to redirect all requests from the old site to the new one. Here is my .htaccess file:
Options +FollowSymlinks
RewriteEngine on
redirect / http://www.foxytronics.com
rewritecond %{http_host} ^roboticsguy.com [nc]
rewriterule ^(.*)$ http://www.foxytronics.com/$1 [r=301,nc]
This URL works:
roboticsguy.com/test/
This one doesn't:
www.roboticsguy.com/test/
What's the problem with the rewrite and how should I fix it?
The line rewritecond %{http_host} ^roboticsguy.com [nc] means "only do the next bit if the domain name is roboticsguy.com". www.roboticsguy.com is not the same as roboticsguy.com.
rewritecond %{http_host} ^roboticsguy.com [nc]
rewriterule ^(.*)$ http://www.foxytronics.com/$1 [r=301,nc]
rewritecond %{http_host} ^www.roboticsguy.com [nc]
rewriterule ^(.*)$ http://www.foxytronics.com/$1 [r=301,nc]
or
rewritecond %{http_host} ^(www.)?roboticsguy.com [nc]
rewriterule ^(.*)$ http://www.foxytronics.com/$1 [r=301,nc]
should work.
What I'm trying to achieve is a 301 redirection of all the pages/resources for a domain except the root of the site every page then should move from www.example.com/example.com to old.example.com.
I'm not an htaccess guru but this is the solution I came up with...
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond !^$ [NC]
RewriteRule ^(.*)$ http://old.example.com/$1 [R=301,L]
But seems not to work
You were missing the TestString in the RewriteCond
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
#if not root
RewriteCond %{REQUEST_URI} !^/?$ [NC]
#redirect
RewriteRule ^(.*)$ http://old.example.com/$1 [R=301,L]
I have a joomla 1.6 website, and I want to enforce a www in the beginning of urls.
I've written the following into htaccess:
RewriteCond %{http_host} ^example\.com [nc]
RewriteRule (.*) http://www.example.com/$1 [r=301,nc]
What it should do is redirect from example.com/happy_bunnies.html to www.example.com/happy_bunnies.html. Instead it redirects to www.example.com/index.php
RewriteCond %{http_host} ^example\.com [nc]
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteRule .* http://www.example.com%1 [r=301,nc,l]
No idea why the first didn't work, but this one does
Have you tried...
RewriteCond %{http_host} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,NC]