1

I want to make a redirect url

From

http://abc.redirect.in/admin/index.php?controller=class&action=add

To

http://abc.redirect.in/admin/class/add

Any idea?

Want to remove text

http://abc.redirect.in/admin/index.php?controller=class&action=add

1
  • Check this out. .htaccess magic examples on Github: github.com/phanan/htaccess Commented Feb 26, 2015 at 20:05

1 Answer 1

2

You can use this code in your /admin/.htaccess file:

RewriteEngine On
RewriteBase /admin/

RewriteCond %{THE_REQUEST} /admin/index\.php\?controller=([^\s&]+)&action=([^\s&]+) [NC]
RewriteRule ^ %1/%2? [R=302,L,NE]

# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?controller=$1&action=$1 [L,QSA]
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for this answer. I tried this. it is giving the pretty url but browser giving me 404 error. On every page I am using $_GET for getting controller and action value.
test.localhost/admin/index.php?controller=pjAdmin&action=pjActionLogin
Then these rules should work. Above URL will be redirected to http://test.localhost/admin/pjAdmin/pjActionLogin in browser? Are you seeing this pretty URL. Then 2nd rule will route it back /admin/index.php. Do you have other rules also in this .htaccess? Or is there any other htaccess?
No it is not redirecting to pretty url. Yes there is other htaccess as well. This is in root directory. Pretty URL htaccess is in inner directory called admin. Root directory is different framework(Yii).
It does work for me. Make sure first 302 rule is very first rule in /admin/.htaccess

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.