1

I have the below line in my htaccess file to clean url and is working very fine but i want to redirect to a page without showing the base file name.

What the code does http://example.com/index/e/dog What am trying to do is to hide the index.php and have a url like this http://example.com/e/dog

RewriteEngine on
RewriteRule ^([^/\.]+)/?$ $1.php  [L,QSA] #remove php extension

RewriteCond %{THE_REQUEST} /index\.php\?e=([^\s&]+) [NC]
RewriteRule ^ /index/e/%1? [R=301,L]
RewriteRule ^index/e/([^/]+)/?$ index.php?e=$1 [L,QSA]

Unclean url http://example.com/index.php?e=dog

Peter
  • 1,860
  • 2
  • 18
  • 47

1 Answers1

0

First, you need to make sure you are linking to /e/dog in your application, and not /index/e/dog. You then basically just need to remove index from your directives. There's also no need for your initial directive that appends the .php extension.

Try the following instead:

RewriteEngine on

# This is optional and only serves to redirect users and search engines
# that have already linked to / indexed the old URL structure.
RewriteCond %{THE_REQUEST} /index\.php\?e=([^\s&]+) [NC]
RewriteRule ^index\.php$ /e/%1? [R=302,L]

# Rewrite URL to actual filesystem path
RewriteRule ^e/([^/]+)/?$ index.php?e=$1 [L,QSA]

Change the 302 (temporary) to 301 (permanent) only when you are sure it's working OK. This is to avoid problems of 301s being cached by the browser.

You will need to clear your browser cache before testing.

MrWhite
  • 43,179
  • 8
  • 60
  • 84