3

I have url Like http://somesite.com/packagemenu.php?conname=domestic-tours-packages&consubname=kerala-tours-packages

Now, i want to make it seo friendly with php code or htaccess rewriterule

my output should be look like this

http://somesite.com/domestic-tours-packages/kerala-tours-packages

2 Answers 2

2

Simply apply the rewrite rule like this:

RewriteEngine On
RewriteRule    ^([^/\.]+)/([^/\.]+)$    packagemenu.php?conname=$1&consubname=$2    [NC,L]  
Sign up to request clarification or add additional context in comments.

6 Comments

can i test that in staging website because my htaccess are not working i've tried this but without [NC,L].i've tried this htaccess code but it's not working.
@RushabhShah It does work for me. I don't know in which way you way its not working. Have you entered http://somesite.com/domestic-tours-packages/kerala-tours-packages in the URL?
Hey thank you!! it worked!! but css and js are not loading!
what if there is multiple pages like packagemenu.php then somepage.php ? i have tried RewriteRule ^([^/\.]+)$ packagedetails.php?pid=$1 [L] RewriteRule ^([^/\.]+)/([^/\.]+)$ packagemenu.php?conname=$1&consubname=$2 [NC,L]
Actually this is another question, you need to provide on which condition it needs to be redirected to packagedetails and for which condition, it needs to be redirected to packagemenu.
|
1

If you want to redirect from querystring to short url, Try the following

 RewriteEngine on

RewriteCond %{THE_REQUEST} /packagemenu.php\?conname=([^&]+)&consubname=([^\s]+) [NC]
RewriteRule ^ /%1/%2? [NC,L,R]

#skip the rule if the request is for dir
RewriteCond %{REQUEST_FILENAME} !-d

 #skip the rule if the request is for file
 RewriteCond %{REQUEST_FILENAME} !-f
 #rewrite any other request  to "/packagemenu.php?" 
 RewriteRule ^([^/]+)/([^/]+)/?$ /packagemenu.php?conname=$1&consubname=$2 [NC,L]

shortest way to do it is as above!

3 Comments

trying this one!! thanx for reply!!
@rushabhshah the accepted answer is not the shortest way ,its a half way to do this rewriting. You can still access your url with query strings.ex : example.com/file.php?q=foo is still redirecting to example.com/file.php?q=foo, google will index both urls. my code is a little diffrent and complete ,it redirects example.com/file.php?q=foo to example.com/foo SEF, and search engine will index just 1 example.com/foo not example.com/file.php?q=foo
yes but it's not working! i can still open querystring when i injected this code in htaccess and i also want the same for single querystring i customized this code but it didn't work!

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.