htaccess 301 redirect to home 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/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]

Related

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/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]

301 redirecting in htaccess for redirecting url

i want to redirect this please guide me
form
http://example.com/babycare/testimonials.php?id=7
to
http://example.com/babycare/testimonial/cat/1
To redirect
http://example.com/babycare/testimonials.php?id=7
to
http://example.com/babycare/testimonial/cat/1
You can use the following rule :
RewriteEngine on
RewriteCond %{THE_REQUEST} /babycare/testimonials\.php\?id=([0-9]+) [NC]
RewriteRule ^ /babycare/testimonial/cat/%1? [L,R]

htaccess 301 redirect to index page

I need the sloution for home page 301 redirection.
If I enter http://www.starmed.dk/index.php in the browse bar, then it will be redirected to http://www.starmed.dk without index.php
Any idea how to do this with an HTACCESS 301 redirect?
Thanks in advance.
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^starmed.dk[nc]
RewriteRule ^(.*)$ http://www.starmed.dk/$1 [r=301,nc]
//301 Redirect Old File
Redirect 301 www.starmed.dk/index.php www.starmed.dk
Edit:
Perhaps your configuration is different. perhaps this:
RewriteRule ^www.starmed.dk/index.php$ www.starmed.dk/ [R=301]
Try the following :
DirectoryIndexRedirect Off
RewriteEngine on
RewriteRule ^index\.php$ / [L,R]

Remove 'index.php' from url without removing parameters in .htaccess

I have a condition for url redirect like,
www.domain.com/something/anotherthing/index.php
i need the above url to redirect to
www.domain.com/something/anotherthing/
If i go to
www.domain.com/index.php/something/anotherthing
i want to redirect to
www.domain.com/something/anotherthing
i have a redirect htaccess rule for this
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index.php$1 [NC]
RewriteRule ^ /%1$1 [R=301,L]
But this works for the first condition but in the later it redirect me to the root page. Can anyone please help in this redirection.
Thanks in Advance.
Try something like this:
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index.php/?([^\ \?]*) [NC]
RewriteRule ^ %1/%2 [R=301,L]
That should handle any location of /index.php.

Resources