How do 301 redirect with .htaccess? - .htaccess

I have url
/en/parlour-profile/massage-parlour-anna-berry-massage-louise-sensual-massage%E2%80%8B
and I try
Redirect 301 /en/parlour-profile/massage-parlour-anna-berry-massage-louise-sensual-massage\%E2\%80\%8B /en
or
RewriteCond %{THE_REQUEST} ^\w+ /en/parlour-profile/massage-parlour-anna-berry-massage-louise-sensual-massage%E2%80%8B
RewriteRule ^ /en [R=301,L]
or
Redirect 301 /en/parlour-profile/massage-parlour-anna-berry-massage-louise-sensual-massage\%E2\%80\%8B /en
But any version don't work. How I can redirect from this url?

You can use this rule as your first rule in site root .htaccess:
RewriteEngine On
RewriteRule ^en/parlour-profile/massage-parlour-anna-berry-massage-louise-sensual-massage\xE2\x80\x8B/?$ /en? [L,NC,R=301]
\xMN is used in RewriteRule pattern to match %MN in URL.

Related

301 Redirect in htaccess to remove URL Parameter? And redirect to original URL

I have following pattern of URLs in some of my WordPress site
abc.com/xolo-lt900-price-in-india.html? m=1
and
abc.com/xolo-lt900-price-in-india.html? m=0
I want to remove part which is after parameter value and 301 redirect it to main/original URL.
So,
bc.com/xolo-lt900-price-in-india.html?m=1
Shall 301 redirect to
abc.comprice4india.co.in/xolo-lt900-price-in-india.html
And in same way
abc.com/xolo-lt900-price-in-india.html? m=0
Shall 301 redirect to
abc.com/xolo-lt900-price-in-india.html
I have the following code but its not working.
RewriteCond %{QUERY_STRING} m [NC]
RewriteRule ^$ /? [R=301,L]
Thanksfully the old code from #Anubhava is working now..
RewriteCond %{QUERY_STRING} ^m=[01]$ [NC]
RewriteRule ^(.*)$ /$1? [R=301,L,NC]

htaccess 301 redirect to home/index page

I need the solution for home page 301 redirection.
If I enter like below url in the browse bar
http://www.starmed.dk/index.php/component/restaurantguide/tags/tags/2-kebab?sem_midx=-3&sem_jidx=-1
http://www.starmed.dk/index.php/about-us/restaurant/faq.php
http://www.starmed.dk/index.php/about-us/tags/18-pizzeria
http://www.starmed.dk/index.php/about-us/tags/9-online-shop
http://www.starmed.dk/index.php/tilfoj-din-butik/city/47-odder?sem_midx=-1&sem_jidx=-3&format=feed&type=atom
http://www.starmed.dk/index.php/component/restaurantguide/recipes/recipes/20-ca-nuong-trui-bare-fried-fish?sem_midx=3&sem_jidx=1
http://www.starmed.dk/index.php/tilfoj-din-butik/city/95-kalundborg?sem_midx=-6&sem_jidx=0
http://www.starmed.dk/index.php/component/restaurantguide/restaurant/1-frederiks-have?sem_midx=2&sem_jidx=1
http://www.starmed.dk/index.php/tilfoj-din-butik/tags/faq.php
http://www.starmed.dk/?index%5c.php%25253Fid=3-yorkshire-savings-account.83&xzaty=3&article=83
http://www.starmed.dk/?option=com_restaurantguide&view=states&id=450:midtjylland
http://www.starmed.dk/index.php?cPath=56
http://www.starmed.dk/index.php?cPath=25
http://www.starmed.dk/index.php?cPath=47
and etc...
If I enter after index.php some values like mentoned above example
then it will be redirected to http://www.starmed.dk without index.php
How to do this using HTACCESS 301 redirect common rule?
You can use this rule to remove index.php from your URL:
RewriteEngine On
# remove index.php, MAKE SURE THIS IS YOUR FIRST RULE
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ %1 [L,R=301,NE]

Dymanic URL htaccess 301 redirects

I have multi-url redirects and I need to make 301 redirects from?
RewriteRule ^car/([^/]+)/model-([^/]+)-([0-9]+)/$ new_car.php? model=$1&name=$2&year=$3 [QSA,L]
You can use the the following :
#1 301 redirect from the old location to the new
RewriteCond %{THE_REQUEST} /new_car\.php\?model=([^&]+)&name=([^&]+)&year=([^&\s]+) [NC]
RewriteRule ^ /car/%1/model-%2-%3/? [L,R=301]
#2 internally redirect from the new location to the old
RewriteRule ^car/([^/]+)/model-([^/]+)-([0-9]+)/?$ new_car.php? model=$1&name=$2&year=$3 [QSA,L]

301 from mobile=N in htaccess

I wanted to make a 301 from URL with ?mobile=N parameter to URL without that parameter. Google is indexing this URL and I think that 301 is the best way to fix that
eg.
FROM
www.example.com/?mobile=N
TO
www.example.com
FROM
www.example.com/example/example.com?mobile=N
TO
www.example.com/example/example.com
You can use in your .htaccess:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^mobile=N$ [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L]

How to point two urls into one using htaccess

I'm trying to redirect to url to a single new url
http://www.domain.com/ --> http://www.domain.com/v3/
http://www.domain.com/v2 --> http://www.domain.com/v3/
Here's what I did
RewriteEngine on
RewriteRule ^v2/(.*) http://www.domain.com/v3/ [R=301,L]
RewriteRule ^(.*) http://www.domain.com/v3/ [R=301,L]
Try this:
Redirect 301 /v2 http://domain.com/v3
Redirect 301 / http://domain.com/v3/

Resources