My actual htaccess redirect my complete old site to my new site, I want to redirect all domain but except two file .php (protectetfile1.php and protectedfile2.php).
This is my htaccess
RewriteEngine On
Rewritecond %{http_host} ^olddomain.org [NC]
Rewriterule ^(.*)$ http://newdomain.net/$1 [L,R=301]
Use this rule:
RewriteEngine On
Rewritecond %{http_host} ^olddomain\.org [NC]
RewriteCond %{REQUEST_URI} !/(protectetfile1|protectetfile2)\.php [NC]
Rewriterule ^(.*)$ http://newdomain.net/$1 [L,R=301]
Related
I need to redirect all my users to another site keeping the current page structure in order to redirect them to the right page on the new domain.
My goal is redirect only the main domain, not the subdomain so I create this snippet but I'm not sure this is right:
RewriteCond %{HTTP_HOST} domain.com
RewriteRule /(.*) http://otherdomain.com [R=301,L]
I already have this in my htaccess that redirect users from www to non-www site:
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
How can I make sure that if a user comes from www.domain.com he will be redirect to the new domain?
You can place new rule just below earlier rule like this:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule (.*) http://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule (.*) http://otherdomain.com/$1 [R=301,L]
However if there is only one domain hosted then you can replace those 2 rules by this single rule:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule (.*) http://otherdomain.com/$1 [R=301,L]
I have been attempting (without success) to implement the following logic in .htaccess:
www.domain.com/aa/ redirects to www2.domain.com/aa/
www.domain.com/bb/ redirects to www3.domain.com/bb/
www.domain.com/cc/ redirects to www4.domain.com/cc/
www.domain.com/dd/ redirects to www4.domain.com/dd/
www.domain.com/ee/ redirects to www4.domain.com/ee/
.htaccess rules also needs to preserve all directories/page names in the URL:
www.domain.com/aa/collectionA/productB
redirects to
www2.domain.com/aa/collectionA/productB
www.domain.com/bb/collectionC/productD
redirects to
www3.domain.com/bb/collectionC/productD
www.domain.com/cc/collectionD/productE
redirects to
www4.domain.com/cc/collectionD/productE
Any solutions would be most welcome! Thank you.
Place this code in your DOCUMENT_ROOT/.htaccess file of domain.com:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^aa(/.*)?$ http://www2.domain.com%{REQUEST_URI} [NC,NE,R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^bb(/.*)?$ http://www3.domain.com%{REQUEST_URI} [NC,NE,R=301,L]
Place this code in your /cc/.htaccess, /dd/.htaccess and /ee/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^ http://www4.domain.com%{REQUEST_URI} [NC,NE,R=301,L]
Update: As per comments you can have this rule in root .htaccessof each domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www2\.domain\.com$ [NC]
RewriteRule ^/?$ /aa/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www3\.domain\.com$ [NC]
RewriteRule ^/?$ /ab/ [R=301,L]
I would like to redirect my domain name from one site to another. I only want the rule to be applied if no other subpages are specified
EG:
www.example.com
would get redirected
www.example.com/folder/page.php
would not get redirected
The code I have does a catch all and that is not what I want
RewriteCond %{HTTP_HOST} ^oldsite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^(.*)$ http://newsite.com/folder/$1 [L,R=301]
You can use:
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com [NC]
RewriteRule ^/?$ http://newsite.com/folder/ [L,R=301]
I have an .htaccess file for some domains sitting on same folder but leads to different content that is determined by php according to the domain name.
I want only one of them to redirect all requests to ssl domain.
How that's can be done?
When I use redirect rules it transfer all domains:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%mydomain.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%mydomain.com%{REQUEST_URI} [L,R=301]
If you want to skip mydomain.com from this http->https redirection:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?mydomain\.com$
RewriteCond %{HTTPS} off
RewriteRule ^ https://%mydomain.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%mydomain.com%{REQUEST_URI} [L,R=301]
We made a mistake in the scope of our dynamic pages on a new site, and have some incorrect pages already spidered in Google.
I need to redirect the following format:
http://www.domain.com/dir/dir/?q=120
To this format:
http://www.domain.com/dir/dir/?p=120
Only difference is the 'q' needs to be a 'p'.
RewriteEngine is on, as I've already consolidated traffic from domain.com to www.domain.com
This is what I have in my root .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^centerline.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteRule ^(/leadership/detail/)\?q=([0-9]+)$ $1?p=$2 [R=301, L]
Try this:
RewriteCond %{QUERY_STRING} q=([0-9]+)$
RewriteRule ^(.*)$ /$1?p=%1 [L,R=301]
You'll need the RewriteCond as apache doesn't allow matching against the querystring in a RewriteRule
EDIT
RewriteCond %{REQUEST_URI} ^/leadership/detail/$
RewriteCond %{QUERY_STRING} q=([0-9]+)$
RewriteRule ^(.*)$ /$1?p=%1 [L,R=301]