I have a problem in Rewrite URL. I have hyperlink & URL like 172.16.2.44/restaurant/home.php?state_id=3&city_id=7 here state_id & city_id are not fixed. now i want this URL like 172.16.2.44/restaurant/home.php/3/7
This is actually a quite common use of the .htaccess modrewrite. Let me quick find a good tutorial that explains this....here's one: http://www.tutorio.com/tutorial/search-engine-friendly-urls-with-mod-rewrite You will want to use code like this: Options +FollowSymLinks RewriteEngine On RewriteRule ^restaurant/home.php/([0-9]+)/([0-9A-Za-z]+)/ restaurant/home.php?state_id=$1&city_id=$2 You may need to modify that slightly, but just check some other modrewrite tutorials.
Ya, if you are on a linux server it's best to use htaccess if you have that capability, but there are other options for ASP, windows servers, etc. This is a good resource I always utilize http://www.bigoakinc.com/blog/how-to-do-a-301-redirect/
thourgh programming also u can create functionality in back end with old url, new url and update button
You need to be careful when you start rewriting URLs like this. How you implement it might depend on whether it is 1) a brand new site where you've NEVER exposed the non-SEO friendly URLs (like 172.16.2.44/restaurant/home.php?state_id=3&city_id=7) or 2) an old site that previously used non-SEO friendly urls (like 172.16.2.44/restaurant/home.php?state_id=3&city_id=7) that you are now converting to SEO friendly URLs. The solutions for these two scenarios are usually different. A brand new site where you've NEVER exposed the non-SEO friendly URLs This is the easier of the two situations described above to deal with. Since no one has ever seen the non-SEO friendly URLs you'll be rewriting to, you really only have to implement URL rewriting from the SEO friendly URL (172.16.2.44/restaurant/home.php/3/7) to the non-SEO friendly URLs (172.16.2.44/restaurant/home.php?state_id=3&city_id=7). I think vansterdam is close... not sure why there is A-Za-z in the $2 pattern match though... and I would allow an optional trailing '/' since the last part of the URI does not have a file extension (Others might interpret it as a folder name and include a trailing '/' when linking to it). So I would guess the following might be a little more correct (but I haven't tested it so...): Hopefully the example above is NOT your real life problem you're trying to solve and is only an example you threw out. I really don't see either of the above as being SEO friendly URLs. I don't think going from 172.16.2.44/restaurant/home.php?state_id=3&city_id=7 to 172.16.2.44/restaurant/home.php/3/7 adds any SEO benefit at all. I personally don't care for filenames in the middle of my URL either like 172.16.2.44/restaurant/home.php/3/7. But that is just me. I think the following would be MUCH more SEO friendly: 172.16.2.44/restaurant/new-york/ithica/ or 172.16.2.44/restaurant/ny/ithica/ You can use the RewriteMap directive in Mod Rewrite to lookup the number that equates to a state name or abbreviation as well as the number that equates to the city. The lookup can be done by referencing a text map file or by calling an executable to, say, lookup the cross-reference from a database. These are very useful for situations where you want to map a text value (like "new-york" or "ny") to a totally different value (like 3). Converting an old site that previously used non-SEO friendly URLs to using SEO friendly URLs: This presents a bit more of a challenge since your non-SEO friendly URLs are out there in the wild. In these situations you need to implement a 301 redirect AND a URL rewrite for every URL. If other sites are already linking to you with URLs like 172.16.2.44/restaurant/home.php?state_id=3&city_id=7 then you will want to implement a 301 redirect from 172.16.2.44/restaurant/home.php?state_id=3&city_id=7 to your SEO friendly URL like 172.16.2.44/restaurant/ny/ithica/. Then when the browser requests 172.16.2.44/restaurant/ny/ithica/ you will want to URL rewrite it back to 172.16.2.44/restaurant/home.php?state_id=3&city_id=7. This will get the non-SEO friendly URL out of Google's index and give credit to 172.16.2.44/restaurant/ny/ithica/ for all inbound links to 172.16.2.44/restaurant/home.php?state_id=3&city_id=7. When you create the rewrite rule and conditions to 301 from 172.16.2.44/restaurant/home.php?state_id=3&city_id=7 to 172.16.2.44/restaurant/ny/ithica/ I would not assume that the query string parameters state_id and city_id will always appear in the same order. More than likely, the following two query strings will return the same content: 172.16.2.44/restaurant/home.php?state_id=3&city_id=7 172.16.2.44/restaurant/home.php?city_id=7&state_id=3 So build your rules appropriately.
I simply write this code.. Options +FollowSymLinks RewriteEngine On RewriteRule ^restaurant/home.php/([0-9]+)/([0-9A-Za-z]+)/ restaurant/home.php?state_id=$1&city_id=$2 But it says Server Error. My question any other document i have to write here.
I write this .htaccess file. But its not working. Options -Indexes Options +FollowSymLinks <IfModule mod_rewrite.c> <IfModule mod_dir.c> DirectoryIndex index.php index.html index.htm default.htm default.html default.asp /mtview.php </IfModule> RewriteEngine on RewriteRule ^restaurant/home.php/([0-9]+)/([0-9A-Za-z]+)/ restaurant/home.php?state_id=$1&city_id=$2 </IfModule>
Some hosting providers would expect you to define a RewriteBase Try adding this just after RewriteEngine on; RewriteBase /