I'm trying to redirect the www and non-www version of my .fr url to a .com url. the www works, but I can 't get the non-www working. Any idea why the non-www Rewrite isn't working?
RewriteCond %{HTTP_HOST} ^www\.domain\.fr$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain\.fr$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
Complete .htaccess
# Helicon ISAPI_Rewrite configuration file
# Version 3.1.0.44
RewriteEngine on
RewriteLogLevel 0
LogLevel debug
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.domain\.fr|domain\.fr)$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.domain.co.uk [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.domain.org [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.domain.net [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.domain.de [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.domain.eu [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteRule ^nl/js/(.*)$ /js/$1 [L, NC]
RewriteRule ^fr/js/(.*)$ /js/$1 [L, NC]
RewriteRule ^en/js/(.*)$ /js/$1 [L, NC]
RewriteRule ^nl/images/(.*)$ /images/$1 [L, NC]
RewriteRule ^fr/images/(.*)$ /images/$1 [L, NC]
RewriteRule ^en/images/(.*)$ /images/$1 [L, NC]
And a bunch of rewrite rules like this
RewriteRule ^nl/news.asp$ n_news.asp [R]
RewriteRule ^fr/news.asp$ f_news.asp [R]
RewriteRule ^en/news.asp$ e_news.asp [R]
As I understand (based on your htaccess) all what you want to do is to redirect ANY configured domain name to www.domain.com.
In this case try this single rule instead of separate rule for each TLD (co.uk, .org, .eu etc) that you have:
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
So anything that is not www.domain.com will be redirected to it.
Related
Here is my Rewrite Rule :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule "^/q/(a-zA-Z0-9)*/?$" "/#/q/$1"
Something does not work, I don't understand what.
I want to redirect /q/xxx to /#/q/xxx
How can I do it ?
here is the solution: RewriteRule ^q/([a-zA-Z0-9-]+)/?$ /#/q/$1 [L,NC,R=301,NE]
The flags were missing
I have a subdomain created to use as cookiless domain which is like cdn.domain.com
And on the main site I have www.domain.com. Whatever I call it comes as www.cdn.domain.com. I am using cdn.domain.com to call images etc.
Here you can see actual htaccess setting
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond $1 !^(index\.php|images|robots|public|sitemap.xml|favicon.ico|\.txt|\.html)
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
</IfModule>
How I can get https://cdn.domain.com without affectting any change to main domain settings?
I think you're looking for this:
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
Your htaccess would look like this now:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond $1 !^(index\.php|images|robots|public|sitemap.xml|favicon.ico|\.txt|\.html)
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
</IfModule>
I want to force redirect any visit to my site to https.
My htaccess rules are the following:
# rewrite address
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mytestsite\.eu$ [NC]
RewriteRule ^(.*)$ https://www.mytestsite.eu/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ https://www.mytestsite.eu/$1 [R=301,L]
#RewriteCond %{HTTP_HOST} ^(.+)\.mytestsite\.eu$ [NC]
#RewriteCond %{HTTP_HOST} !^www\.
#RewriteRule ^ https://www.mytestsite.eu/ [L,R]
how can I achieve this?
rewrite the first three lines like this:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
myhtaccess code contains:
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} www\.
RewriteRule ^ http://xyz23465.com%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{HTTP_HOST} ^52\.71\.19\.242
RewriteRule (.*) http://xyz23465.com/$1 [R=301,L]
But when I type https://www.xyz23465.com it redirects me to http://xyz23465.com/http://www.xyz23465.com/ which becomes a url not found.
Could you please suggest?
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]