RedirectMatch 301 in htaccess file - .htaccess

Can anyone tell me what does
RedirectMatch 301 /([a-zA-Z_]+)-(\d+)-(\d+)-1-([a-z]+)-([a-zA-Z_]+).html http://www.example.com/$1-$2-$3-$4-$5.html
mean in .htaccess file??

This regex is searching for:
[anyChars and_]-[digits]-[digits]-1-[smallChars and_]-[anyChars and_].html
and redirects browser. Ex:
*aaAA-1234-567-1-bbb-cC_c.html*
will be redirected to:
*http://www.example.com/aaAA-1234-567-bbb-cC_c.html*
Also here is a good service to test RegEx: http://gskinner.com/RegExr/

Related

Change Directory with Wildcard Redirect using RedirectMatch not working

I am trying to use a RedirectMatch to redirect all files under one directory to the main directory:
RedirectMatch 301 ^/question/.*$ https://www.sample.com/
So that if I have a URL like www.sample.com/question/what-day-is-it
It will automatically redirect to www.sample.com/what-day-is-it
The problem is when I put in the RedirectMatch like above, it redirects all URLs to the homepage: www.sample.com/question/what-day-is-it to www.sample.com
If anyone else had the same problem, a simple Redirect 301 /question / did the trick.

htaccess redirect 301 and rewrite

I am trying to simplify URLs from
xyz.com/walks/walk_descrip/8010/
to
xyz.com/walk-8010
I have moved the file from the walks sub-directory to the root.
I have tried using the following in my htaccess file
Redirect 301 ^/walks/walk_descrip/(.*)/$ /walk-$1
RewriteRule ^walk-(.*)$ /walk-description.php?id=$
However this is producing URLs such as
xyz.com/walk-8010?id=8010
Where am I going wrong?
Any help would be appreciated
Redirect directive doesnt support regex. What you are looking for is RedirectMatch.
RedirectMatch 301 ^/walks/walk_descrip/(.+)$ /walk-$1

HTACCESS rewrite, select after a specific character

I'm trying to create a 301 redirect for some old URLs. An example of an old URL:
http://www.example.com/forum/news/555-subject-test
I want to redirect this to:
http://www.example.com/news/subject-test
I have this:
RedirectMatch 301 /forum/news/(.*)-(.*) /news/$1
However this redirects it to http://www.example.com/forum/news/test
Any ideas how I can fix this? Thank you!
You can use:
RedirectMatch 301 ^/forum/news/[0-9]+-(.+)$ /news/$1
rather than:
RedirectMatch 301 /forum/news/(.*)-(.*) /news/$1

redirectmacth problems with quotes

google indexed link:
http://domain.com/category/body-cosmetics/„gloria“-good-quality
I need to redirect to:
http://domain.com/category/body-cosmetics/gloria-good-quality
In htaccess I have code:
RedirectMatch 301 http://domain.com/category/body-cosmetics/(.*)gloria(.*)-good-quality http://www.domain.com/category/body-cosmetics/gloria-good-quality
But its not working...
any ideas ?
Try without the hostname and scheme:
RedirectMatch 301 ^/category/body-cosmetics/(.*)gloria(.*)-good-quality$ http://www.domain.com/category/body-cosmetics/gloria-good-quality

Redirect directory to the same directory but in a subfolder using htaccess

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.

Resources