I am using below rule to redirect my url
Redirect 301 /crm /crm/applications
But the resulting url because of rule is
http://www.site_url.com/crm/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications/applications
How to solve this issue?
Use RedirectMatch instead,
RedirectMatch 301 ^/crm$ /crm/applications
It provides regular expression based match which can help zero down on specific pattern using ^ and $ anchors.
Related
I'm trying to redirect this url:
https:///www.domain.com/courses/company/
to this one:
https:///www.domain.com/courses/
without also redirecting these:
https:///www.domain.com/courses/company/123/
https:///www.domain.com/courses/company/456/
I first tried this:
Redirect 301 /courses/company/ /courses/
but that also redirected the urls with the subdirectories.
Next I tried this:
Redirect 301 /courses/company/$ /courses/ ...because I thought the $ sign makes it match exactly that url.
But it didn't redirect anything.
Thanks!
The issue with the Redirect directive is that it does not allow to use "regular expressions" as you tried to do. It only implements a simple prefix string matching approach.
Instead you'd have to use the RedirectMatch directive which does support such expressions:
RedirectMatch 301 ^/courses/company/?$ /courses/
See the documentation of the RedirectMatch directive.
Instead you could also use the more flexible rewrite module:
RewriteEngine on
RewriteRule ^/?courses/company/?$ courses/ [L,R=301]
And a general hint: it usually is a good idea to start out with a 302 temporary redirection. And to only change that to the 301 permanent redirection once everything works as intended. That prevents nasty caching issues for your clients.
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]
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
I'm trying to 301 redirect from '/en' or '/en/' to '/en/home' using .htaccess, but any attempt I do results into a redirection loop '/en/home/home/home/home/home/home...'.Shouldn't it be as simple as Redirect 301 /en /en/home?
Redirect based rule keep matching /en in redirected URL as well. You can use RedirectMatch for this with regex support:
RedirectMatch 301 ^/(en)/?$ /$1/home
Also make sure to clear your browser cache when you test this.
You have to use the full URL, example:
redirect 301 /folder_wrong/name.html http://website.com/folder-right/name.html
Lets take the following example:
Redirect 301 /crowdfund/ http://website.com/crowdfund/browse/
Currently its creating a redirect in this format:
http://website.com/crowdfund/browse/browse/browse/browse/browse/browse/browse/browse/browse/browse/browse/browse/browse/browse/browse/browse/browse/browse/browse/browse/browse/
What am i doing wrong here?
Thanks!
Use RedirectMatch for exact regex match instead:
RedirectMatch 301 ^/crowdfund/?$ http://website.com/crowdfund/browse/
In your rule /crowdfund/ is being matched before and after redirect.