Rewrite rule causing a loop - .htaccess

We have an online shop with a welcome page. Our SEO company has asked us to get rid of the welcome page with a rewrite as follows. i am struggling to get this to work. Can you help please?
rewrite www.domain.co.uk/catalog/index.php to become www.domain.co.uk, then 301 from www.domain.co.uk/catalog/index.php to www.domain.co.uk.
I have the following code which causes a redirect loop and nothing is displayed
RewriteRule ^/?$ catalog/index.php [L]
Redirect 301 /catalog/index.php http://www.domain.co.uk
Thanks in advance

How's that?
RewriteCond %{REQUEST_URI} /catalog/
RewriteRule .* / [L,R=301]
RewriteRule ^/?$ catalog/index.php [L]
If catalog is part of the browser request, a 301 will correctly redirect to /, which in turn will rewrite to catalog/index.php.

Related

htaccess 301 redirect rules issue

I am trying to do a simple redirection, but I encounter this error, when I do the 301 redirect using the htaccess, it returns the redirect but with the value
.htaccess
RewriteRule ^clientes/(\w+)/?$ clientes.php?id=$1 [L]
Redirect 301 /clientes/juan http://google.es
result:
https://www.google.es/?id=juan&gws_rd=ssl
It's because you are mixing mod-alias (Redirect) with mod-rewrite (RewriteRule) . These are two diffrent modules with diffrent runtime behaviour .
Try using this :
RewriteRule ^clientes/juan http://google.com [L,R=301]
RewriteRule ^clientes/(\w+)/?$ clientes.php?id=$1 [L]
Clear your browser cache before testing these rules.
this working, but my problem is with this line.
Rewriterule ^videos/(.*)_(.*).html$ index.php?tag=$1&page=$2 [L,NC]
Rewriterule ^videos/(.*).html$ index.php?tag=$1 [L,NC]
RewriteRule ^/videos/juan.html https://www.dominio .com/cat/conduccion-juan/ [R=301,L]
and this not working
redirect 301 /videos/juan.html https://www.dominio.com/videos/conduccion-juan.html
thank you!

301 redirect complete url to different extension, BUT with exceptions

I'm trying to 301-redirect a whole website to a different extension (org to com) while I'm keeping everything after the subdomain. That works. For example: www.oldsite.org/somepage redirects to www.newsite.com/somepage.
But I want some pages be to excluded from this rule, for example /sub1/ has to redirect to /sub2/ I tried it with the following code, but it didn't work. Any thoughts on this?
RewriteEngine on
RewriteRule ^(.*)$ http://newsite.com/$1 [R=301,L]
Redirect 301 /sub1/ http://www.newsite.com/sub2
Cheers!
You can use:
RewriteEngine on
RewriteRule ^sub1(/.*)?$ http://www.newsite.com/sub2$1 [R=301,L]
RewriteRule ^(.*)$ http://newsite.com/$1 [R=301,L]
Also works for:
/sub1 -> http://www.newsite.com/sub2
/sub1/etc/etc -> http://www.newsite.com/sub2/etc/etc

How can I redirect a subdomain to a specific URL?

I am updating the Iirf.ini file to redirect sub.columbia.edu to giving.columbia.edu/video.
sub.columbia.edu is already redirecting to giving.columbia.edu.
How can I go one step further to redirect it to giving.columbia.edu/video.
Important Note: I would like the URL to show as sub.columbia.edu in the browser and not as giving.columbia.edu/video
#Redirect subdomain to specific URL
RewriteCond %{HTTP_HOST} ^sub\.columbia\.edu
RewriteRule ^/$ /video
The above doesn't work. Any ideas how I should modify this?
Thank you!
You can try this and see how it works for you.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.columbia\.edu
RewriteRule ^(.*) http://giving.columbia.edu/video [L,R=301]
Or you can do a redirect, this should work also.
Redirect 301 / http://giving.columbia.edu/video

.htaccess 301 redirect from old url to SEO friendly

I have link like this:
www.site.com/page.php?p=1
Need to rewrite it to friendly URLs in htaccess
RewriteRule ^home$ page.php?p=1
It works but now I have two active links with the same content.
Tried to add 301 redirect from old link to new but stuck in loop. Any ideas how to fix that?
Try matching against the actual request so that your rules won't loop:
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /page\.php\?p=1(&|\ |^)([^\ ]*)
RewriteRule ^page\.php$ /home?%3 [L,R=301]
# then your internal rewrite
RewriteRule ^home$ page.php?p=1
Remove the redirect on the page and handle it in the htaccess.
RewriteRule ^page\.php\?p=1$ /home [L,R=301]
This will redirect to /home and stop the redirect loop you have now.
another quick & dirty way to prevent looping in these situations i've found is to add a querystring and then check for its existence in the redirect.
RewriteCond %{QUERY_STRING} ^p=1
RewriteCond %{QUERY_STRING} !foo=bar
RewriteRule ^page\.php$ /home [NC,R=301,L]
RewriteRule ^home$ page.php?p=1&foo=bar [NC,L]
found on this site: http://answers.oreilly.com/topic/542-how-to-properly-redirect-for-maximum-seo/
Redirect 301 /page.php?p=1 www.yourwebsite.com/home?p=1 RewriteRule
^home?p=1$ /page.php?p=1

How can I redirect old pages with question marks in the URL?

I have read about htaccess redirect and rewrite on stackoverflow and on other sites and learned how to redirect simple pages and directories, but there are about 30 links remaining that I haven't been able to redirect. The reason appears to be because they contain "?" in the link's URL. I've tried the solutions posted but I haven't been able to make enough sense of them to succeed.
These work:
Redirect /Corpfleet.php htp://www.marketyourcar.cm/wraps.php
Redirect /drivers.php htp://www.marketyourcar.cm/drivers.php
Redirect /galleries.php htp://www.marketyourcar.cm/galleries.php
These do NOT work:
Redirect /ad.php?View=FAQ htp://www.marketyourcar.cm/advertiser-faqs.php
Redirect /ad.php?View=gallery htp://www.marketyourcar.cm/galleries.php
Redirect /ad.php?View=Materials htp://www.marketyourcar.cm/products-services.php
Yes, I know that the URL above is htp and .cm - I had to break it in order to make this post with my low reputation level.
If anyone can help with this I'd appreciate it.
Thanks
If you want to redirect from like:
site.com/index.php?blabla=1&id=32
to
site.com/contact.html
then use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} blabla=1&id=32
RewriteRule ^(.*)$ http://www.site.com/contact.html? [R=301,L]
</IfModule>
Redirect can't handle that. RewriteRule can. This should work.
RewriteEngine on
RewriteRule ^/ad\.php\?View\=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php [R=301,L]
RewriteRule ^/ad\.php\?View\=gallery$ http://www.marketyourcar.cm/galleries.php [R=301,L]
RewriteRule ^/ad\.php\?View\=Materials$ http://www.marketyourcar.cm/products-services.php [R=301,L]
Or try this:
RewriteEngine on
RewriteRule ^/ad.php?View=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php [R=301,L]
RewriteRule ^/ad.php?View=gallery$ http://www.marketyourcar.cm/galleries.php [R=301,L]
RewriteRule ^/ad.php?View=Materials$ http://www.marketyourcar.cm/products-services.php [R=301,L]
This might work:
Example:
RewriteEngine On
RewriteRule ^/ad.php?View=FAQ$ http://www.marketyourcar.cm/advertiser-faqs.php? [R=301,L]
Add a trailing ? to the substitution URL to remove the incoming query.

Resources