BuildMyWeb Posted September 10, 2013 Share Posted September 10, 2013 i know the answer has to be here, or elsewhere on the web, but ive searched both for the last hour and im more confused than when i started. i read this as well and it cleared some things up relating to other issues but not this issue: http://corz.org/serv/tricks/htaccess2.php anywho, my problem is i have a php site where we pass GET values in the URL. we dont want users to see the ugly URLs however. so for instance, this is the current URL: "http://mysite.com/details.php?prod=36271" and we want to write a line it htaccess that rewrites the URL to: "http://mysite.com/a-nicer-url" is the above even possible? this is my best attempt thus far: Options +FollowSymlinks RewriteEngine On RewriteCond %{REQUEST_URI} ^details\.php\?prod=36271$ RewriteRule /a-nicer-url/%1 [L,R] Quote Link to comment https://forums.phpfreaks.com/topic/282053-rewriting-dynamic-url-to-static/ Share on other sites More sharing options...
requinix Posted September 10, 2013 Share Posted September 10, 2013 It's certainly possible but we need to know more. What kind of URLs do you want? Creating a new RewriteRule for everything is crazy (unless there's a very small number of them and they won't change) so you need something more dynamic than "a-nicer-url maps to product 36271". To do that there are two basic options: 1. The new URLs need to have the same information present in the old URLs but in a different form, like "/product/36271", with even more information than that if you want. 2. You alter the details.php to accept a different set of information that you do put in the new URL. Like if product #36271 is called "a-nicer-url" then you can do that, but you have to edit the script to know to look for the name instead of the ID. Also consider a URL that isn't at the top level of the website, like /product/36271 or /product/a-nicer-url. Cleaner that way. Quote Link to comment https://forums.phpfreaks.com/topic/282053-rewriting-dynamic-url-to-static/#findComment-1449028 Share on other sites More sharing options...
BuildMyWeb Posted September 10, 2013 Author Share Posted September 10, 2013 there is an SEO party involved that wants specific replacements for these dynamic URLs and the replacements are not necessarily of any pattern that i can write a regexpression for. some have the id# in the new URL (in the above case "36271") and others dont. i also didnt want to track down every link on the site that uses the old URL and replace it with a static one. ie. find all instances of "/details.php?prod=36271" and in the HTML replace with "/a-nicer-url" there is only a product line of about 40 items so crazy as it seemed, i was considering writing up to 40 individual rewrites Quote Link to comment https://forums.phpfreaks.com/topic/282053-rewriting-dynamic-url-to-static/#findComment-1449039 Share on other sites More sharing options...
kicken Posted September 11, 2013 Share Posted September 11, 2013 If you have a bunch of arbitrary redirections with no real pattern, you may just need to generate a bunch of rewrite entries for each url (or use RewriteMap) Quote Link to comment https://forums.phpfreaks.com/topic/282053-rewriting-dynamic-url-to-static/#findComment-1449075 Share on other sites More sharing options...
BuildMyWeb Posted September 12, 2013 Author Share Posted September 12, 2013 i didnt want to track down every link on the site that uses the old URL and replace it with a static one. that was my objective. but it sounds like from what you guys are advising, i will have to do that in this scenario. thanks for the advice. i appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/282053-rewriting-dynamic-url-to-static/#findComment-1449299 Share on other sites More sharing options...
jazzman1 Posted September 16, 2013 Share Posted September 16, 2013 You should know, that you need to have an access to apache .conf file to use the RewriteMap directive. I'm find it for very useful solution in your case. Context: server config, virtual host Quote Link to comment https://forums.phpfreaks.com/topic/282053-rewriting-dynamic-url-to-static/#findComment-1449622 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.