I'm trying to apply a redirect rule using redirectmatch 301 like below
RedirectMatch 301 ^/product-category/babies-tots/ https://mothersenvogue.com.hk/shop/all-babies-tots?
It does work. However, the appended query string like the example below does not get stripped.
http://mev-hongkong.com/product-category/babies-tots/?add_to_wishlist=8836
How can I strip the ?add_to_wishlist=8836 parameter to just redirect it to https://mothersenvogue.com.hk/shop/all-babies-tots/ ?
Related
I have in .htaccess a redirect that should transform the url with .html in without extension which works great.
RedirectMatch 301 ^/([^/]+)/([^/]+)\.html$ /$1/$2/
I want to exclude from the rule if the filename it's named index.html how do I do that?
What I tried was
RedirectMatch 301 ^/([^/]+)/(?!index|[^/]+)\.html$ /$1/$2/
But now it isn't working at all.
You may use this regex in your rule:
RedirectMatch 301 ^/([^/]+)/(?!index)([^/]+)\.html$ /$1/$2/
Your attempts at negative lookahead doesn't seem to be correct because of | in expression.
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 have a redirectMatch rule in place:
RedirectMatch 301 /dir/subdir/safety-program(.*) /dir/subdir/safety-program/$1
When I load the safety-program address, like so:
http://localhost/dir/subdir/saftey-program/
or
http://localhost/dir/subdir/saftey-program
I get the safety-program page returned with the following address, with an extra trailing slash:
http://localhost/dir/subdir/safety-program//
Why is the match adding that second slash? How do I remove it?
the problem is here safety-program/$1 and it should be like this safety-program$1
why you should change it
the RedirectMatch comes like this
RedirectMatch [status] regex URL
So the [status] is: 301 and regex is : /dir/subdir/safety-program(.*) then there is a url which is : /dir/subdir/safety-program/$1 and this part, $1, of url will match this part ,(.*), of regex , so you put slash in this (.*) then it comes to url like this $1 including that slash , and you expressed about it like this /$1 in url , so that why double slash occurred.
That what you did exactly.
Whenever request /dir/subdir/safety-program/ it would be /dir/subdir/safety-program//
so change the line code to be :
RedirectMatch 301 /dir/subdir/safety-program(.*) /dir/subdir/safety-program$1
OR this :
RedirectMatch 301 /dir/subdir/safety-program/(.*) /dir/subdir/safety-program/$1
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
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.