I have a QR code that I need to redirect to a new page. For some reason the redirect is being overridden (ends up at cmdgroup.com/community instead of the appropritate page)
RewriteCond %{HTTP_HOST} ^(.*)?companies/Inova-Solutions-Inc/Network-Clocks-by-Inova-Solutions/53e4f5e048e43c1d5cef656d [NC]
RewriteRule ^(.*)$ http://www.cmdgroup.com/companies/1142841/inova-solutions-inc/ [R=301,L]
RewriteCond %{HTTP_HOST} ^(.*)?community.cmdgroup.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(.*)?community.reedconstructiondata.com [NC]
RewriteRule ^(.*)$ http://www.cmdgroup.com/community/ [R=301,L]
It is because your first RewriteCond %{HTTP_HOST} is wrong since you only match domain name using %{HTTP_HOST} variable. Change that rule to this:
RewriteRule companies/Inova-Solutions-Inc/Network-Clocks-by-Inova-Solutions/53e4f5e048e43c1d5cef656d$ http://www.cmdgroup.com/companies/1142841/inova-solutions-inc/ [R=301,L]
RewriteCond %{HTTP_HOST} community\.(cmdgroup|reedconstructiondata)\.com$ [NC]
RewriteRule ^ http://www.cmdgroup.com/community/ [R=301,L]
Related
I have this code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
What this does is:
With http://example.com it redirects to https://www.example.com (this is correct)
With https://example.com it redirects to https://www.example.com (this is correct)
But with http://www.example.com it doesn't redirect to https://www.example.com.
Please take note that It needs to be not more than 1 chain. It should redirect to https://www.example.com.
You can avoid hardcoding your host name and do both conditions in a single redirect rule like this:
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
Okay I just fixed it.
this is the updated code
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
I can guarantee that this will all do 301 redirect without more than 1 chain.
I hope this helps some developers out there!.
I have this code to force any URL to be "https://www.":
#rewrite to WWW:
RewriteCond %{HTTP_HOST} !^(\d+)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTP_HOST} !^(\d+)
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I have sub-domains and I do not want any of them to be redirected. What can I do?
You can do it all in single rule:
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(?:static\.|subdomain1\.|subdomain2\.|\d+) [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301,NE]
Make sure to clear your browser cache before testing this rule.
Is there a way I can simplify this code so I dont have to check .com and .org separately?
RewriteCond %{HTTP_HOST} ^(www\.)?mywebsite\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/mydirectory(/.*)?$ [NC]
RewriteRule ^(.*)$ /mydirectory/$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mywebsite\.org$ [NC]
RewriteCond %{REQUEST_URI} !^/mydirectory(/.*)?$ [NC]
RewriteRule ^(.*)$ /mydirectory/$1 [QSA,L]
Yes you can take regex help for that. Try this:
RewriteCond %{HTTP_HOST} ^(www\.)?mywebsite\.(com|org)$ [NC]
RewriteCond %{REQUEST_URI} !^/mydirectory(/.*)?$ [NC]
RewriteRule ^(.*)$ /mydirectory/$1 [L]
Take note of (org|com) which makes that patter match both .org and .com
The problem is that following .htaccess syntax:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} robots.txt$ [NC]
RewriteRule ^([^/]+) $1 [L]
RewriteCond %{HTTP_HOST} ^bd-spb\.ru$ [NC]
RewriteRule ^(.*)$ http://xn----8sbbkdenhe5aqs7a.xn--p1ai/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.bd-spb\.ru$ [NC]
RewriteRule ^(.*)$ http://xn----8sbbkdenhe5aqs7a.xn--p1ai/$1 [R=301,L]
Redirects only index page. So if I go to bd-spb.ru I will get бизнес-диалог.рф, but if I go for example here its not redirects me here.
How to make this happens?
Ok replace your code with this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} robots\.txt$ [NC]
RewriteRule ^([^/]+) $1 [L]
RewriteCond %{HTTP_HOST} ^(www\.)?bd-spb\.ru$ [NC]
RewriteRule ^(.*)$ http://xn----8sbbkdenhe5aqs7a.xn--p1ai/$1 [R=301,L,B]
Hi guys I a major issue with url rewrite. Apologizes if you might have seen this somewhere before.
issue here
If i enter a url for example exampl.x10.mx OR www.example.x10.mx I get a 403 error which shouldnt happen because
RewriteCond %{HTTP_HOST} ^example.x10.mx [NC]
RewriteRule ^(.*)$ http://www.example.x10.mx/$1 [R=301,L]
is MIGHT to take care of that.
RewriteCond %{REQUEST_URI} !^lwh/
RewriteCond $1 !^lwh/
The code above hiden the lwh folder.
FULL .htaccess CODE
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !^lwh/
RewriteCond $1 !^lwh/
RewriteCond %{HTTP_HOST} ^example.x10.mx [NC]
RewriteRule (.*) /lwh/main/pages/general/$1 [L]
RewriteRule ^(.*)$ lwh/$1 [L]
RewriteRule ^(.*)$ http://www.example.x10.mx/$1 [R=301,L]
Summary of the problem
If i remember
RewriteCond %{REQUEST_URI} !^lwh/
RewriteRule ^(.*)$ lwh/$1 [L]
the code below works and the same happens if i remember the code below. The thing is I need both of them.
RewriteCond %{HTTP_HOST} ^example.x10.mx [NC]
RewriteRule ^(.*)$ http://www.example.x10.mx/$1 [R=301,L]
An idea why this is happening please
Replace your .htaccess with this code:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.x10\.mx$ [NC]
RewriteRule ^(.*)$ http://www.example.x10.mx/$1 [R=302,L]
RewriteCond %{REQUEST_URI} !^/lwh/
RewriteCond %{HTTP_HOST} ^example\.x10\.mx$ [NC]
RewriteRule ^(.*)$ /lwh/main/pages/general/$1 [L]
The problem was with the
R=301 (permanent redirect to new URL)
Before
RewriteRule ^(.*)$ http://www.example.x10.mx/$1 [R=302,L]
now
RewriteRule ^(.*)$ http://www.example.x10.mx/$1 [L]