Redirect duplicate urls using htaccess - apache

i need help with htaccess advanced redirect.
Like i have some pages in my blog,
URL example site.com/en/post-detail/90
User can access same page by link
site.com/en/post-detail/90/(anything after slash)
so i want to redirect all requests like
site.com/en/post-detail/90/(anything) to site.com/en/post-detail/90.
/en/ - is various, it can be Ru, pt, it, fr etc.
/90/ - is the id of post, so it is always numbers

Try :
RedirectMatch 301 ^/((en|ru|pt|it|fr)/post-detail/([0-9]+))/.+$ /$1

Related

htaccess redirecting website.com/folder/content to subdomain.website.com/content

I recently moved a Wordpress blog from website.com/wordpress to help.website.com. Now I want to redirect the links to the old adress to the new adress.
I deleted everything from the /wordpress folder except the .htaccess. This file has the following code:
RedirectMatch 301 (.*) http://www.help.website.com$1
It redirects my old links but I don't know how to remove the /wordpress from them.
For example if I access website.com/wordpress/article-categories/example-article/ it sends me to help.website.com/wordpress/article-categories/example-article/, but I want to get to help.website.com/article-categories/example-article/ instead. How do I achieve this?
Try
RedirectMatch 301 ^/wordpress/(.*)$ http://www.help.website.com/$1
This will match the folder literally without capturing it.

Custom .htaccess hidden 301 redirect

Is it possible to write in one rule the redirecting for each brand alias to an equivalent get-parameter?
For example:
"/katalog/protein/api/" must be redirected to "/katalog/protein/?ms|manufacturer=API",
"/katalog/protein/activelab/" must be redirected to "/katalog/protein/?ms|manufacturer=ActiveLab"
I'm looking for something like that in .htaccess:
RewriteRule ^katalog/(protein|gainer)/(api==API|activelab==ActiveLab)/?$ /katalog/$1/?ms|manufacturer=$2 [R=301,L,QSA,NE,NC]
Is it possible? Thank's for any help.

301 Redirect A URL Pattern Using .htaccess

I want to redirect my URLs to a new pattern. For this purpose, I used 301 redirect for every single URL but that are taking a huge time and my .htaccess file is going large and large as I have thousands of URLs.
So now Someone said to me to use .htaccess to use 301 redirect or rewrite engine option. Now I am new to .htaccess to use Pattern Redirect. First of all clear me out that is this possible to use 301 redirect in patterns? If yes then Can I do pattern 301 redirect in the below URLs? I want to redirect the below pattern so can you help me?
/search/label/XXXXXXXXXX to /category/XXXXXXXXXX
/year/month/XXXXXXXXXX.html/?m=0 to /year/month/XXXXXXXXXX.html
/year/month/XXXXXXXXXX.html/?m=1 to /year/month/XXXXXXXXXX.html
/search to /
/feed to /
XXXXXXXXXX means some text/no that are dynamic and changeable. year and month means only no that are also dynamic and changeable. / means site homepage. Rest are fixed text.
Please keep in mind that sometime there are many variables in every URL so we also want to avoid that that always start from ?variable=value&variable=value in the end of every URL.
After asking here, I keep trying myself too so I am able to do it and working on my side. I added below codes in my .htaccess file and after that I am able to redirect all upper URLs without any 404 error.
Redirect 301 /search/label http://www.example.com/category
Redirect 301 /search http://www.example.com
Redirect 301 /feed http://www.example.com
For 2,3 URL pattern, I did nothing because after checking, its not showing any 404 error as they are only variable in front of URL so no need to edit that.

Apache modrewrite rule for redirect from a dynamic .asp to main url

I'm on a linux server now and have moved from a .asp environment cms and now need to redirect old .asp urls from about 20 pages that look like this: http://www.iwanet.org/argomento.asp?cat=38 and want it to redirect to http://iwanet.org/profdevel . There are several unique id's (cat=22, cat=2, cat=1 ) after the iwanet.org/argumento.asp? is the same so just need everything after the question mark ?= so I need a catch-all redirect url for everything after the equal sign.
This should do the trick
RewriteEngine On
RewriteRule ^/?argomento\.asp$ /profdevel [QSA,R=301,L]
This will route all requests to /argomento.asp to /profdevel with a 301 redirect and append the query string (with QSA flag).

301 redirect with {~`% characters in url

Trying to apply a 301 redirect to this url "/Qx%40w%2C6M42VAwp3%40Rb%7B~cC4ure%60QWI9" but it's not liking it, i'm guessing because of the horrible url and all the strange characters in it, any ideas?
This is the code I currently have:
redirect 302 /Qx%40w%2C6M42VAwp3%40Rb%7B~cC4ure%60QWI9 /product-tool-case.php
You can do this with mod_rewrite as follows:
RewriteRule ^/Qx%40w%2C6M42VAwp3%40Rb%7B~cC4ure%60QWI9 /product-tool-case.php
I?f you want to continue using mod_alias as above, then you should ensure that the old url is url-decoded. So in the above example try:
redirect 302 /Qx#w,6M42VAwp3#Rb{~cC4ure`QWI9 /product-tool-case.php