I am looking for a Regex to redirect urls like:
example.net/example-1
example.net/example-2
example.net/example-3
I have many URLs that have the same prefix, but a different suffix after example-.
I was trying around with regex.
Redirect 301 /example-.*$ http://example.net/example-overview
Redirect 301 /example-(.*)? http://example.net/example-overview
Redirect 301 /example-(.+)[/]?$ http://example.net/example-overview
Redirect 301 /([^/example-]+) http://example.net/example-overview
I can't get it work.
Normal redirects for example example-1 to example-overview are working fine.
EDIT:
Found a solution:
RedirectMatch 301 ^/example-(.+)[/]?$ http://example.net/example-overview
Redirect doesn't support regular expressions, use RedirectMatch for that.
Related
I have urls like this
https://www.example.co.uk/382-princeton-teak-6ft-garden-bench-chinoiserie-bench.html
That i want to redirect to
https://www.example.co.uk/princeton-teak-6ft-garden-bench-chinoiserie-bench.html
I tried with RedirectMatch 301 ^/(.+?)([0-9]+)-(.*)\.html$ /$1.html it do match but it redirects to https://www.example.co.uk/3.html any thoughts guys ?
You should be using this rule as number is right at the start:
RedirectMatch 301 ^/[0-9]+-(.+\.html)$ /$1
Clear your browser cache to test this change.
End of the url have numbers without any separator
Given url like
example.com/productdetails/product-flowers123
needed to redirect
example.com/productdetails/product-flowers--123
can i do this with .htaccess
I already tried: RedirectMatch 301 ^/productdetails/([A-Za-z]+)$([0-9]+)$ /productdetails/$1--$2
But its not worked.
You can use this rule instead:
RedirectMatch 301 ^/(productdetails/.*?[a-zA-Z])([0-9]+)/?$ /$1-$2
Make sure to use a new browser or clear your browser cache before testing this change.
I have the below URL
http://www.yyyyy.com/en/x/y/2010/2010-02-03-test
And I want to redirect it to
https://www.yyyyy.com/x/y/2010-02-03-test
So what I need to do is, remove the /en/ part from the URL
I need the regular expression to add on .htaccess file that can help me to do 301 redirects for this,
You can use the following redirect:
RedirectMatch ^/en/x/y/2010/(.+)$ /x/y/$1
I'm using RedirectMatch 301 to redirect requests like mydomain.com/example to an example page. For that I'm using the following code in my .htaccess file:
RedirectMatch 301 (?i)/whatever http://thedomain.com
The (?i) is so that the redirect is case-insensitive. What I want to achieve now is that that only works when the /whatever is put directly after mydomain.com, so mydomain.com/sub/sub/whatever won't redirect the user.
Thanks in advance
Use regex anchors to restrict your match:
RedirectMatch 301 ^(?i)/whatever/?$ http://thedomain.com
Is there any way I can do all the following ( and similar ) redirects with a rule
Redirect 301 brand/brand1 http://domain.com/department/brand1
Redirect 301 brand/brand2 http://domain.com/department/brand2
Redirect 301 brand/brand3 http://domain.com/department/brand3
Yes you can use RedirectMatch that gives your regex capabilities like this:
RedirectMatch 301 brand/([^/]+) http://domain.com/department/$1