kampbell411 Posted October 31, 2011 Share Posted October 31, 2011 Hi, I am going crazy over how to rewrite and hide a directory name in a URL. I am trying to rewrite the following: domain.com/city/FL/Miami.html to domain.com/FL/Miami.html Quote Link to comment https://forums.phpfreaks.com/topic/250169-rewrite-rule-help/ Share on other sites More sharing options...
cags Posted November 2, 2011 Share Posted November 2, 2011 Are you saying that on your server you have a directory in your root called city that has an FL folder with a Miami.html file inside of it and that you wish the url to appear as just /FL/Miami.html without the word city? RewriteEngine On RewriteRule ^(FL/Miami\.html)$ /city/$1 [L] I assume you have more than just the one URL you wish to rewrite, but since you didn't specify any parameters, I'm not going to bother hypothesising as I could be completely off. Either way it's just a matter of creating the correct regular expression to match the first half. Quote Link to comment https://forums.phpfreaks.com/topic/250169-rewrite-rule-help/#findComment-1284396 Share on other sites More sharing options...
kampbell411 Posted November 3, 2011 Author Share Posted November 3, 2011 Your right sorry. Here is basically all the details. I am trying to write while passing two variables, a state abbreviation and a city name. http://www.example.com/city/{stateAbreviation}{cityName}.html to http://www.example.com/{stateAbreviation}{cityName}.html I am linking to http://www.example.com/city/{stateAbreviation}{cityName}.html from http://www.example.com/state/{stateAbreviation}.html as http://www.example.com/{stateAbreviation}{cityName}.html but I am getting a 404. Here is what I tried in my root htaccess of my domain but it didn't work. Should I try putting an htaccess in my city directory? RewriteRule ^([A-Z]{2})/(.*)\.html /city/index.php?st=$1&id=$2 [L] also tried RewriteRule ^(.*)/(.*)\.html /city/index.php?st=$1&id=$2 [L] Quote Link to comment https://forums.phpfreaks.com/topic/250169-rewrite-rule-help/#findComment-1284470 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.