Reputation: 1587
My url is
http://localhost/site.in/names-in.php?loc=kochi
My required url is
http://localhost/site.in/names-in/kochi
I have this in .htaccess
which unfortunately not working.
Options +FollowSymLinks
RewriteEngine on
RewriteRule names-in/(.*)/ names-in.php?loc=$1
I have this in page print_r($_GET);
which shows empty array. Any inputs why its not working?
Upvotes: 1
Views: 59
Reputation: 4917
Your original RewriteRule is not being met. You can achieve this using {QUERY_STRING}
instead:
RewirteEngine On
RewriteCond %{QUERY_STRING} loc=(.+)$ [NC]
RewriteRule ^(.*)$ /names-in/%1 [R=301,L,QSD]
Then to internally rewrite the URL:
RewriteRule ^/names-in/([^/]*) /names-in.php?loc=$1 [L]
Make sure you clear your cache before testing this. This is using R=301
which is a permanent redirection, I advise you change this to R=302
while testing, as this is temporary.
I've also added ?
onto the end of the rewritten URL. This is to stop the original query appearing on the end of the URL.
Upvotes: 2
Reputation: 1267
Try this
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^names-in/(\d+)*$ ./names-in.php?loc=$1
#RewriteRule ^names-in/(.*)$ ./names.php.php?loc=$1
you can access from http://localhost/site.in/names-in/kochi
Upvotes: 0