1

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?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

7 Comments

Unfortunatly its throwing 500 - Internal server error
Do you have anything else in your .htaccess? Or just this rule?
Nothing, just this
Sorry for the late response. I've made an edit as I'd forgotten to add the [NE] flag the the rewrite rule. Try now.
Thx for your time, unfortunately I am still getting 500 error
|
0

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

5 Comments

try printing print_r($_REQUEST)
Is site.in folder name ?
Yes, it is under localhost root
I have updated code, Can you try again with above code
still empty array ` Array ( )`

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.