ERR_TOO_MANY_REDIRECTS [duplicate] - .htaccess

I want to make a redirect 301 from an old ulr to a new url.
old url: /php/zend-framework/captcha-codigo-anti-spam-zend-framework
new url: http://www.demo31.com/blog/php/zend-framework/captcha-codigo-anti-spam-zend-framework
In .htaccess I make this redirect like this ...
RedirectMatch 301 /php/zend-framework/captcha-codigo-anti-spam-zend-framework http://www.demo31.com/blog/php/zend-framework/captcha-codigo-anti-spam-zend-framework
But I've got the error "ERR_TOO_MANY_REDIRECTS".
What am I doing wrong?

It looks like both URI's are on the same host (www.demo31.com), so when you use RedirectMatch, the part of the URI that matches is part of the redirect. Example
If I go to:
http://www.demo31.com/php/zend-framework/captcha-codigo-anti-spam-zend-framework
The URI is /php/zend-framework/captcha-codigo-anti-spam-zend-framework
The RedirectMatch directive matches the URI, redirects to:
http://www.demo31.com/blog/php/zend-framework/captcha-codigo-anti-spam-zend-framework
new URI is /blog/php/zend-framework/captcha-codigo-anti-spam-zend-framework
however, the RedirectMatch directive matches the URI again since it contaings /php/zend-framework/captcha-codigo-anti-spam-zend-framework
Try changing RedirectMatch to just Redirect. Or if you only want that specific URI to redirect (as opposed to something like /php/zend-framework/captcha-codigo-anti-spam-zend-framework/some/other/stuff also getting redirected, add a few delimiters:
RedirectMatch 301 ^/php/zend-framework/captcha-codigo-anti-spam-zend-framework$ http://www.demo31.com/blog/php/zend-framework/captcha-codigo-anti-spam-zend-framework
(the ^ and $

RewriteRule ^bad_url$ good_url [R=301,L]
Thx ! works for me

Related

How to implement 301 permanent redirection using htaccess with custom parameter in URL?

Here I have a URL like www.abc.com/product/women/casual/page:5/ and I need to implement 301 permanent redirection using htaccess in order to change the URL to www.abc.com/product/women/casual/page/5/. In this case, parameter women and casual is customized category and subcategory and page:5 is page number 5. I need to change the last parameter page:5 to page/5 using htaccess 301 permanent redirection. Can anyone please help me to find a solution for the case.
You can use the following redirect :
RedirectMatch 301 ^/([^:]+):5/$ /$1/5/
Or a more generic one:
RedirectMatch 301 ^/([^:]+):([0-9])/?$ /$1/$2
This will redirect your old URL to the new one , for example example.com/foo/bar:digit/ to example.com/foo/bar/digit/ .
Or you can use RewriteRule directive
RewriteEngine on
RewriteRule ^([^:]+):5/$ /$1/5/ [R=301,L]

htaccess redirecting previous URLs to single URL

After deploying a new site, I'm working to redirect old urls to a single page. Trying both redirects and rewrites. Desired:
/oldurl/page1 => /newurl
/oldurl/page2 => /newurl
The following redirect works, but not entirely. For example:
Redirect 301 /oldurl /newurl
Becomes the following, where page1 should actually be removed
/newurl/page1
The following rewrite doesn't rewrite at all:
RewriteRule ^oldurl/(.*)$ /newurl [R=301,NC,L]
You can use RedirectMatch for this to get more control via regex patterns:
RedirectMatch 301 ^/oldurl(/.*)?$ /newurl

When I use 301 redirect, I get the wrong url address

My redirect is as follows:
Redirect 301 / http://testsite.com/en/
I get the following address: testsite.com/en/en/en/en/en/en/en/en
I worked in a .htaccess file. Where is my mistake?
You should use RedirectMatch to target precise URL using regex:
RedirectMatch 301 ^/$ http://testsite.com/en/
Make sure to test this after clearing your browser cache.

.htaccess RedirectMatch redirects all pages like "something"

I want to redirect
mysite.com/something
to
othersite.com/someone
I am using this (in htaccess):
RedirectMatch 301 /something http://othersite.com/someone
but it redirects all pages like mysite.com/ksadkahsdhasdhkas/something and I want to redirect only mysite.com/something
How to do it?
Use regex anchors ^ and $ to make sure you don't match any unwanted URI:
RedirectMatch 301 ^/something/?$ http://othersite.com/someone

.htaccess to pass FULL URL into other PHP link as $_GET

From .htacces file, how to pass/redirect the FULL URL to another URL as GET Variable?
Like:
http://www.test.com/foo/bar.asp
will be redirected to:
http://www.newsite.com/?url=http://www.test.com/foo/bar.asp
With Full Url with Domain.I tried:
RewriteEngine on
RedirectMatch 301 ^/(.*)\.asp http://www.newsite.com/?url=%{REQUEST_URI}
But it is going out like:
http://www.newsite.com/?url=?%{REQUEST_URI}
RewriteEngine on
RedirectMatch 301 ^/(.*)\.asp http://www.newsite.com/?url=$1.asp
If the initial domain and protocol is always the same then you can use
RedirectMatch 301 ^/(.*)\.asp http://www.newsite.com/?url=http%3A%2F%2Fwww.test.com%2F$1\.asp

Resources