I am trying to redirect an entire subdirectory to our main domain.
Basically links like this:
https://garrysun.com/dev/ayurveda-products/categories/ayurvedic-ghee-clarified-butter?limit=15
https://garrysun.com/dev/
https://garrysun.com/dev/ayurveda-products/
Should all go to
https://garrysun.com/
We are using OpenCart 2.3.0.2
I have tried:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/dev/(.*)$
RewriteRule ^(.*) https://garrysun.com/ [R=301,NC]
and
RewriteRule ^dev/(.*)$ https://garrysun.com [R=301,NC,L]
But neither seems to work. What is the best .htaccess rule to make this work?
Inside /dev/.htaccess have this single rule:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?garrysun\.com$ [NC]
RewriteRule ^ https://garrysun.com/? [R=301,L]
Your web server appears to be Nginx as per the response headers. For Nginx use this rule:
location ~ ^/dev/ {
return 301 https://garrysun.com/?;
}
I used this redirect:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)$ /$1 [R=301,L]
The problem is that if the page doesn't exist in the main website I get a 404 error.
For example:
This: https://garrysun.com/dev/777-oil-psoriasis
Becomes this: https://garrysun.com/777-oil-psoriasis
I get a 404 error because that page doesn't exist on the main site.
This works:
https://garrysun.com/dev/ayurveda-products/
Becomes:
https://garrysun.com/ayurveda-products/
because the new site has that page.
Related
I am trying to redirect the following (respectively):
http://sub.firstdomain.com/d/(all_files_and_folders)
http://sub.firstdomain.com/d2/(all_files_and_folders)
to
http://sub.seconddomain.com/d/(all_files_and_folders)
http://sub.seconddomain.com/d2/(all_files_and_folders)
There are other files and folders under the first subdomain that I do not want redirected. Previously this was working but now it seems like Go Daddy changed something and what I had is no longer working. Here it is:
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^stats/(.+) /dstats/count.php?statspage=$1 [L,NC,QSA]
RewriteRule ^(.+)\.deb$ /dstats/count.php?file=$1.deb [L,NC,QSA]
RewriteCond %{HTTP_HOST} ^sub\.
RewriteRule ^(d2?)/(.*)$ http://sub.seconddomain.com/$1/$2 [L,R=301]
You can ignore the RewriteRule. It is working fine. I wanted to make sure I included the entire .htaccess file just in case. My issue is with RewriteCond it seems.
The following should work:
RewriteEngine On
Redirect 301 /d/ http://sub.seconddomain.com/d/
Redirect 301 /d2/ http://sub.seconddomain.com/d2/
The above should only redirect anything in the /d/ and /d2/ folder of the sub subdomain.
EDIT: Second try
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub1\.
RewriteRule ^(d2?)/(.*)$ http://sub2.mydomain.com/$1/$2 [L,R=301]
OK so... I have the following URL which works on my site:
http://my_domain.net/w/mRD3nKkM
The rewrite for this in the root of my site is:
RewriteRule ^([w])/(\w+)$ res/$1/response.php?id=$2 [L]
Simple stuff and works a treat. Now I want to redirect any traffic that hits that URL unencrypted to go over https, like below:
https://my_domain.net/w/mRD3nKkM
So I put another .htaccess file within the res/w/ folder conatining the following:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} ^/response.php$
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^(.*)$ https://my_domain.net/w/$1 [R,L]
To my miind this should work, but doesn't.
To be clear, I have the following URL rewrite working:
http://my_domain.net/w/mRD3nKkM
and I would like it to look like this:
https://my_domain.net/w/mRD3nKkM
Thanks
You should handle http => https before doing internal forward stuff. Following should work for you:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^w/.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC]
RewriteRule ^(w)/(\w+)/?$ res/$1/response.php?id=$2 [L,NC]
The crawling properties of site showing
http://www.abc.com/http://www.abc.com/index.php?option=com_toys
http://www.abc.com/http://www.abc.com/index.php?option=com_article
http://www.abc.com/http://www.abc.com/index.php?option=com_play&view=category&vid=10
The site been crawled like this, with errors coming in as duplicate url. Correct url is
http://www.abc.com/index.php?option=com_toys
http://www.abc.com/index.php?option=com_article
http://www.abc.com/index.php?option=com_play&view=category&vid=10
is there any way to 301 redirect
i tried using
RewriteCond %{REQUEST_URI} ^.*/http://www.abc.com.*$
RewriteRule .* index.php [R=301,L]
But its not achieving the desired as redirecting to http://www.abc.com/index.php
How to redirect through htaccess from incorrect url to correct url sttructure off site
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+http://.+?(/index\.php\?[^\s]+) [NC]
RewriteRule ^ %1 [R=301,L,NE]
Try this code :
RewriteEngine On
RewriteRule ^http://www.abc.com/index.php /index.php [QSA, R=301]
I am finding some problems in the htaccess of CMS with a 301 redirect.
When trying to solve canonical urls (redirecting site to www.site) I got the problem that I cannot log in in the back end (www.site/admin).
The htaccess condition is:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.site\.co.uk$
RewriteRule (.*) http://www.site.co.uk$1 [R=301,L]
I guess I need to include a expression that allows the URI /admin not to be redirected, but how?
Like this, for example:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !=www.example.co.uk
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule .* http://www.example.co.uk%{REQUEST_URI} [R=301,L]
I have removed the blog from my domain and put a simple index.html instead.
How do I redirect all the incoming traffic so that it does not show a 404 error, but redirects to the index?
I tried this, but it loops...
RewriteEngine on
RewriteRule ^(.*)$ /index.html [L,R=301]
Try:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html
RewriteRule ^(.*)$ /index.html [L,R=301]
As you mentioned that this doesn't work, I'd try:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/aaa.html
RewriteRule ^(.*)$ /aaa.html [L,R=301]
index.html is a general default file name, so there might be rules that are on the server level, not in your .htaccess. That depends on the server setup, though.
Try adding the
Options +FollowSymLinks -MultiViews -Indexes
at the very top and give it a try.