StormTheGates Posted February 5, 2008 Share Posted February 5, 2008 Hello I have a conundrum on my hands. I am searching for a way to turn a url like this: www.ny-mafia.com/city.php?city=Baltimore Into this: www.ny-mafia.com/Baltimore Do you guys have any idea how I could do this? Can it be done with mod_rewrite? Thanks for any help. Quote Link to comment Share on other sites More sharing options...
madmax Posted February 5, 2008 Share Posted February 5, 2008 Presumably you want to change the URL input by the user for "visual effect" - so that the end user sees (in their browser URL bar) the non-PHP parameterised version. Unfortunately this can only be done either by redirecting or by using javascript etc. to control the browser software. Since HTTP is a stateless transaction the browser will know nothing about any rewrites until a redirection is returned. The URL bar will therefore remain unchanged and the user will not see the benefit. If you simply rewrote without redirection back to the browser then the correct location would be accessed by the reference being rewritten a the server end - the user would know nothing about this. Both search engines and user's visual observations would benefit from a redirect I suppose. Yes it could be done using rewrite but - To actually redirect back to another location you might as well use PHP since you are redirecting from a PHP file anyway and can easily construct a header redirect to the uniform folder location. This location would need to host an INDEX.PHP file which then accepts any parameters etc. If no parameters then I'd say a simple INDEX.HTM in there would suffice. Doing it using PHP means CPU time would only be used actually when a hit was made on that page. RewriteRules are processed all the time even if skipped and although the additional CPU overhead is tiny it could mount up on a busy server. Plus the following would be much easier to maintain and would avoid clashes with other rules. For example - something like - (fictitious URL at date of posting) <? $city=$_GET['city']; //Redirect - this causes the remote browser to update the URL bar and redirect the request back to the correct location header("Location: http://www.oregon-bloods.com/$city/"); exit; ?> Just a thought! Quote Link to comment Share on other sites More sharing options...
powerspike Posted February 6, 2008 Share Posted February 6, 2008 I am searching for a way to turn a url like this: www.ny-mafia.com/city.php?city=Baltimore Into this: www.ny-mafia.com/Baltimore RewriteRule ^([a-zA-Z\']+)$ city.php?city=$1 [NC,L] This should work so that www.ny-mafia.com/Baltimore will load the page www.ny-mafia.com/city.php?city=Baltimore Quote Link to comment 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.