Remove 'index.php' from url without removing parameters in .htaccess - .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.

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 redirect to url parameter

Is it possible to redirect with htaccess, from
http://example.com/redirect.php?url=http%3A%2F%2Fanother.com%2Fsmiley.gif
to url parameter,
http://another.com/smiley.gif
Please advice.
You can use this :
RewriteEngine on
RewriteCond %{THE_REQUEST} /redirect\.php\?url=.+([^/]+\.gif)\s [NC]
RewriteRule ^ http://another.com/%1? [NE,L,R]
This will redirect /redirect.php?url=foobar/foobar.gif to http://another.com/foobar.gif .

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]

php - Htaccess as fake directories

I am making a mini blog that could make it's url looks like this:
From: http://127.0.0.1/index.php?post=the-story-of-us
To: http://127.0.0.1/view/the-story-of-us
I have tried this but i'm getting 404 not found.
RewriteEngine on
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /index\.php\?post=([^&]+)
RewriteRule ^ /view/%2/? [L,R=301]
Your current rule only handles the case: Redirect old url to new url.
(By the way, +1 for using THE_REQUEST to avoid a redirect loop)
You also need to handle the case: Rewrite (internally) new url to old url.
Here is how your htaccess should look like
RewriteEngine On
# Redirect /index.php?post=XXX to /view/XXX
RewriteCond %{THE_REQUEST} \s/index\.php\?post=([^&\s]+)\s [NC]
RewriteRule ^ /view/%1? [L,R=301]
# Internally rewrite back /view/XXX to /index.php?post=XXX
RewriteRule ^view/([^/]+)$ /index.php?post=$1 [L]
I do not udnerstand your RewriteCondition, but the RewriteRule should look like this:
RewriteEngine on
RewriteBase /
RewriteRule ^view/(.*)/? ./index.php?post=$1 [L,R=301]

htaccess redirection help needed

I have a dynamic url domain.com/product/Paper_Bags/Merchandise_Bags_-_Matte_Colors/6_25__X_9_25_/Misty_Grey?7. Which when called need to redirect to domain.com/paper-merchandise-bags-plain-white/
I am using the condition and the rule as
RewriteCond %{QUERY_STRING} (.*)$
RewriteRule ^(.*)/Misty_Grey http://domain.com/paper-merchandise-bags-plain-white/? [R=301,L]
But its not working. Can Someone help me to solve this issue.
If i use RedirectMatch ^(.*)/Misty_Grey http://domain.com/paper-merchandise-bags-plain-white/
Its getting redirected to http://domain.com/paper-merchandise-bags-plain-white/?7
Is there any way to remove the ?7 so tha the querystring will not be visible
Try the following commands,
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com[nc]
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
//301 Redirect Old File
Redirect 301 http://domain.com/product/Paper_Bags/Merchandise_Bags_-_Matte_Colors/6_25__X_9_25_/Misty_Grey?7 http://domain.com/paper-merchandise-bags-plain-white/?

Resources