htaccess 301 redirect to home/index page - .htaccess

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]

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]

Dynamic url's redirect from old to new url's using .htaccess

I want to redirect below two dynamic url from old url's to new url's using .htaccess and i have done this application using codeigniter.
1) This are the dynamic url's and there are more than thousands of url's in my database.
Old(From) URL
https://www.example.com/area-name/pangothe-263001
New(To) URL
https://www.example.com/pangothe-263001
2) This are the amp version of the above url.
Old(From) URL
https://www.example.com/amp-area-name/pangothe-263001
New(To) URL
https://www.example.com/pangothe-263001/amp
I have tried with below code
RewriteRule ^area-name$ http://www.example.com/area-name [R=301,L]
RewriteRule ^amp-area-name$ http://www.example.com/amp-area-name [R=301,L]
But not redirecting to the new urls. How can do this redirect using .htaccess.
Keep these 2 redirect rules just below RewriteEngine line:
RewriteEngine On
RewriteRule ^area-name/(.+)$ /$1 [R=301,L,NC,NE]
RewriteRule ^amp-area-name/(.+)$ /$1/amp [R=301,L,NC,NE]
# remaining rules go below this
Try This
RewriteRule ^area-name/pangothe-263001/?$ $1/pangothe-263001$2 [R=301,L]
Try with below rules,
Canonical links Redirect
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/area-name/(.*)$
AMP links Redirect
RewriteRule ^ https://www.example.com/%1 [R=301]
RewriteCond %{REQUEST_URI} ^/amp-area-name/(.*)$
RewriteRule ^ https://www.example.com/%1/amp [R=301]

How to force redirect query string URL with htaccess?

I want to redirect example.com/recipes/signup?code=OLD277 to example.com/recipes-user/register How can I achieve it via htacces?
I tried the below code in .htaccess but its not working!
Redirect /recipes/signup?code=OLD277 http://example.com/recipes-user/register
You may use this rule as your topmost rule in site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} /recipes/signup\?code=OLD277\s [NC]
RewriteRule . /recipes-user/register? [R=301,L,NE]

htaccess 301 redirect to home 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/tilfoj-din-butik/city/86-morso?sem_midx=0&sem_jidx=6
http://www.starmed.dk/index.php/component/user/reset?sem_midx=12&sem_jidx=-6
http://www.starmed.dk/index.php/restaurants-in-denmark/restaurant/1-frederiks-have?sem_midx=-1&sem_jidx=-10
then it will be redirected to http://www.starmed.dk without index.php
Any idea how to do this with an HTACCESS 301 redirect for above 3 url to common code?
Thanks in advance.
Edited Code:
I'm using below code.
RewriteCond %{THE_REQUEST} /index\.php/(forside?start=5|tilfoj-din-butik/city/68-middelfart?sem_midx=5&sem_jidx=1|tilfoj-din-butik/city/86-morso?sem_midx=0&sem_jidx=6|restaurants-in-denmark/restaurant/1-frederiks-have?sem_midx=-1&sem_jidx=-10|tilfoj-din-butik/city/92-greve?sem_midx=-1&sem_jidx=1|component/user/register|component/restaurantguide/restaurant/4-bybuens-smorrebrod?sem_midx=-4&sem_jidx=0|restaurants-in-denmark/restaurant/1-frederiks-have?sem_midx=2&sem_jidx=12|tilfoj-din-butik/tags/12-fuldkorn|component/restaurantguide/restaurant/6-cafe-konjak?sem_midx=-1&sem_jidx=0|tetest/city/18-helsingorst|about-us/restaurant/14-mevlana-kulgrill|tilfoj-din-butik/restaurant/1-dilans-pizza?sem_midx=0&sem_jidx=0|component/user/reset?sem_midx=12&sem_jidx=-6|component/restaurantguide/tags/tags/3-udbringning?sem_midx=1&sem_jidx=3|restaurants-in-denmark/restaurant/1-dilans-pizza?sem_midx=2&sem_jidx=4|component/restaurantguide/restaurant/1-frederiks-have?sem_midx=4&sem_jidx=0|component/restaurantguide/testimonial/1-excellent-restaurant?sem_midx=1&sem_jidx=4|takeaway/tags/5-grill) [NC]
RewriteRule ^ /? [L,R=301]
Some condition is working. But some condition is not working.
Not working url
http://www.starmed.dk/index.php/component/restaurantguide/restaurant/6-cafe-konjak?sem_midx=-1&sem_jidx=0
http://www.starmed.dk/index.php/restaurants-in-denmark/restaurant/1-frederiks-have?sem_midx=2&sem_jidx=12
Edited Code 1:
these below url only not working.
http://www.starmed.dk/?option=com_restaurantguide&view=states&id=450:midtjylland
http://www.starmed.dk/?index%5c.php%25253Fid=3-yorkshire-savings-account.83&xzaty=3&article=83
How Can I do rule for above 2 url?
It can be done in a single rule:
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php/(tilfoj-din-butik/city/86-morso\?sem_midx=0&sem_jidx=6|component/user/reset\?sem_midx=12&sem_jidx=-6|restaurants-in-denmark/restaurant/1-frederiks-have\?sem_midx=-1&sem_jidx=-10) [NC]
RewriteRule ^ /? [L,R=301]

301 redirect destination url format

I am trying to do some 301 url redirect at my website, here are the first few lines of the .htaccess file :-
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
Redirect 301 /en/home/index.html /index.php?
Redirect 301 /en/about/product.html /shop?
Redirect 301 /en/member/profile.html /index.php?route=account/account
All the above 3 301 rules works fine. But when I remove the "?" at first and second rule, the redirections fail. So in this case, "?" must be present.
However, if I wish to have the format that is without "?", is it possible?
Also, if I just do url rewrite, but not do 301 redirect, will it still maintain the previous seo achievements?
Try using mod_rewrite instead of mod_alias:
RewriteRule ^en/home/index.html$ /index.php? [L,R=301]
RewriteRule ^en/about/product.html$ /shop? [L,R=301]
RewriteRule ^en/member/profile.html$ /index.php?route=account/account [L,R=301]
You're also going to want those before your index.php routing rule.

Resources