I have the following redirects in my htaccess file
Redirect 301 /communityed/index.htm http://www.domain.com/community_education
Redirect 301 /communityed http://www.domain.com/community_education
Redirect 301 /communityed/visit/index.htm http://www.domain.com/directions/
Redirect 301 /communityed/visit/pdfs/campus_map.pdf http://www.domain.com/images/uploads/pdf/campusmap.pdf
The first two redirects work perfectly, but the last two are not.
When to go domain.com/communityed/visit/index.htm it redirects it to domain.com/community_education/visit/index.htm, but it should go to domain.com/directions
Same thing the 4th redirect as well
http://domain.com/communityed/visit/pdfs/campus_map.pdf redirects to http://www.domain.com/community_education/visit/pdfs/campus_map.pdf, when it should really go to http://www.domain.com/images/uploads/pdf/campusmap.pdf
What am I doing wrong that the last 2 redirects are not working appropriately?
I imagine it has something to do w/ the first two redirects over-riding it, but I am fairly new to redirects.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain.com/.*$ [NC]
RewriteRule \.(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]
Given that your redirects are not standard mod_rewrite looking, I'll assume that the matches are greedy, therefore you should change the odder from finest match to most general.
Redirect 301 /communityed/visit/pdfs/campus_map.pdf http://www.domain.com/images/uploads/pdf/campusmap.pdf
Redirect 301 /communityed/visit/index.htm http://www.domain.com/directions/
Redirect 301 /communityed/index.htm http://www.domain.com/community_education
Redirect 301 /communityed http://www.domain.com/community_education
Related
I saw similar topics but couldn't find a practical answer to my problem.
I'm moving my old website to a new one, and some URLs are changing.
I would like to make a generic 301 redirection to the new domain (because most paths are the same), while individually redirecting some URLs.
Here is what I have on my old website .htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.old\.com$
RewriteRule (.*)$ https://new.com/$1 [R=301,L]
Redirect 301 "/custom/url/" "https://new.com/my-custom-url"
</IfModule>
But the 301 redirects to : https://new.com/custom/url instead of https://new.com/my-custom-url
Some of my URLs also have URL parameters I would like to redirect, such as :
Redirect 301 "/brand.php?name=Example" "https://new.com/Example"
Redirect 301 "/brand.php?name=Example2" "https://new.com/another/url"
which do not seem to work as well.
Thank you very much for your help.
But the 301 redirects to : https://new.com/custom/url instead of https://new.com/my-custom-url
It is because your specific redirect rule appears after generic one. Moreover you are mixing mod_rewrite rules with mod_alias rules and these are invoked at different times.
Have it like this:
RewriteEngine On
# redirect /brand.php?name=Example2 to new.com/another/Example2
RewriteCond %{HTTP_HOST} ^(www\.)?old\.com$ [NC]
RewriteCond %{QUERY_STRING} ^name=(Example2) [NC]
RewriteRule ^brand\.php$ https://new.com/another/%1? [R=301,L,NE]
# redirect /brand.php?name=Example3 to new.com/category/Example3
RewriteCond %{HTTP_HOST} ^(www\.)?old\.com$ [NC]
RewriteCond %{QUERY_STRING} ^name=(Example3) [NC]
RewriteRule ^brand\.php$ https://new.com/category/%1? [R=301,L,NE]
# generic redirect /brand.php?name=Example to new.com/Example2
RewriteCond %{HTTP_HOST} ^(www\.)?old\.com$ [NC]
RewriteCond %{QUERY_STRING} ^name=([^&]+) [NC]
RewriteRule ^brand\.php$ https://new.com/%1? [R=301,L,NE]
# redirect custom URL
RewriteRule ^custom/url/ https://new.com/my-custom-url [R=301,L,NE,NC]
# redirect everything else
RewriteCond %{HTTP_HOST} ^(www\.)?old\.com$ [NC]
RewriteRule ^ https://new.com%{REQUEST_URI} [R=301,L]
Ok, so I've got a stack of htaccess redirects from one domain to another, which for the most part works fine. However, this particular link isn't working:
http://giccampers.com.au/general-trailers/tipper-trailer/
It should take people to this website:
http://blackseriescampertrailers.com.au/
If you go to the main domain of http://giccampers.com.au/ it redirects fine. But I can't seem to get any of the other pages to redirect from that domain.
Here's what I've got (I didn't set these up, btw):
RewriteCond %{HTTP_HOST} ^giccampers.com.au [NC]
RewriteRule ^(.*)$ http://blackseriescampertrailers.com.au/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.giccampers.com.au [NC]
RewriteRule ^(.*)$ http://blackseriescampertrailers.com.au/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^giccampers\.com\.au$ [OR]
RewriteCond %{HTTP_HOST} ^www\.giccampers\.com\.au$
RewriteRule ^/?$ "http\:\/\/www\.blackseriescampertrailers\.com\.au\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^www.giccampers.com.au [NC]
RewriteRule ^(.*)$ http://blackseriescampertrailers.com.au/$1 [L,R=301]
redirect 301 /general-trailers/tipper-trailer/ http://blackseriescampertrailers.com.au/
Any help would be great!
use this
RedirectMatch 301 http://giccampers.com.au/general-trailers/tipper-trailer/ http://blackseriescampertrailers.com.au/
RedirectMatch 301 /general-trailers/tipper-trailer/ http://blackseriescampertrailers.com.au/
or
RedirectMatch 301 /tipper-trailer$ http://blackseriescampertrailers.com.au/
or
RedirectMatch 301 /general-trailers/tipper-trailer(.*)http://blackseriescampertrailers.com.au/
I'm running apache on ubuntu 14.04 and trying to set up 301 redirects. Redirection is working, but not as expected. Here's what I have:
#REDIRECTS
Options +FollowSymLinks
RewriteEngine On
# REMOVES INDEX.PHP
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
# REDIRECT SPECIFIC PAGES
Redirect 301 /main http://mikeheavers.com
Redirect 301 /main/ http://mikeheavers.com
Redirect 301 /main/code http://mikeheavers.com/tutorials.html
Redirect 301 /main/code/ http://mikeheavers.com/tutorials.html
The first two redirect 301s work, but the rest, such as /main/code, try to redirect to http://mikeheavers.com/code and note http://mikeheavers.com/tutorials.html. What am I doing wrong?
update: note that I need to be able to redirect urls both containing and not containing the trailing slash
Don't mix mod_rewrite rules with mod_alias that has Redirect directive. Use this:
#REDIRECTS
Options +FollowSymLinks
RewriteEngine On
# REDIRECT SPECIFIC PAGES
RewriteRule ^main/?$ http://mikeheavers.com [L,NC,R=301]
RewriteRule ^main/code/?$ http://mikeheavers.com/tutorials.html [L,NC,R=301]
# REMOVES INDEX.PHP
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Make sure to clear your browser cache before testing this change.
i have developed a website using codeigniter. Previously the site had a long URL structure so i have made them shorter in the new website.
Although i used the redirect directive in htaccess it gives me a 404 error. I have removed all the old controllers and functions.
below is a few lines from htaccess (there are many urls redirecting to new ones)
RewriteEngine On
# Redirect non-www urls to www
RewriteCond %{HTTP_HOST} ^mysite\.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
#RewriteRule ^([^_]*)_(.*)$ /$1-$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Redirect 301 /payments/charity_and_donations/paid http://www.mysite.com/charity
Redirect 301 /outwards/office_furniture/damaged http://www.mysite.com/office_assets
Redirect 301 /funding/business_and_person/inward http://www.mysite.com/funds
can someone tell me why it is not redirecting from the old to the new and what am i doing wrong?
You need to have your redirecting happen before you route URIs to /index.php. Also, since Redirect is part of mod_alias and your other redirect/routing rule is mod_rewrite, the URI is being processed twice when it's not supposed to. You should just use mod_rewrite and add the rules to the beginning:
RewriteEngine On
# Redirect non-www urls to www
RewriteCond %{HTTP_HOST} ^mysite\.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
RewriteRule ^payments/charity_and_donations/paid http://www.mysite.com/charity [R=301,L]
RewriteRule ^outwards/office_furniture/damaged http://www.mysite.com/office_assets [R=301,L]
RewriteRule ^funding/business_and_person/inward http://www.mysite.com/funds [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Try the below code, this works perfectly for me
RewriteCond %{HTTP_HOST} !^www\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
I am trying to rewrite my .htaccess file to redirect old dynamic URLS to new ones.
I have tried these so far but they are not working as expected. The second rule seems to redirect to the first one.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.mydomain\.com\/$1" [R=301,L]
Redirect 301 /product.php?l=old-product-name1 http://www.mydomain.com/product.php?l=new-product-name1
Redirect 301 /product.php?l=old-product-name2 http://www.mydomain.com/product.php?l=new-product-name2
Can anyone help me redirect these properly?
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.mydomain\.com\/$1" [R=301,L]
RewriteCond %{QUERY_STRING} =l=old-product-name1
RewriteRule ^product.php$ http://www.mydomain.com/product.php?l=new-product-name1 [R=301]