scm22ri Posted December 14, 2012 Share Posted December 14, 2012 Hi, I have a question regarding .htaccess. I'm attempting to make pretty URLS. I'm almost half way there but I can't quite seem to figure how to add a "dash" - to certain keywords. On the below page http://whatsmyowncar...cle-display.php How would I turn http://whatsmyowncar...th.com/new york into http://whatsmyowncarworth.com/new-york Below is my .htaccess file. Any help would be appreciated. Thanks. RewriteEngine On RewriteRule ^([a-zA-Z_]+)$ state.php?state=$1 [L] Quote Link to comment https://forums.phpfreaks.com/topic/272007-htaccess-question/ Share on other sites More sharing options...
mrMarcus Posted December 14, 2012 Share Posted December 14, 2012 Prepend the hyphen: RewriteEngine On RewriteRule ^([-a-zA-Z_]+)$ state.php?state=$1 [L] Or, escape it: RewriteEngine On RewriteRule ^([a-zA-Z_\-]+)$ state.php?state=$1 [L] Quote Link to comment https://forums.phpfreaks.com/topic/272007-htaccess-question/#findComment-1399446 Share on other sites More sharing options...
scm22ri Posted December 15, 2012 Author Share Posted December 15, 2012 (edited) Hey Marcus, Thanks for the help. I did what you said and the URL links work now but the data isn't showing up on my website. Could this be because of the htaccess file? http://whatsmyowncar...om/rhode-island http://whatsmyowncarworth.com/new-york RewriteEngine On RewriteRule ^([-a-zA-Z_]+)$ state.php?state=$1 [L] RewriteRule ^([a-zA-Z_]+)/([a-zA-Z_]+)$ city-breakdown.php?state=$1&city=$2 [L] Edited December 15, 2012 by scm22ri Quote Link to comment https://forums.phpfreaks.com/topic/272007-htaccess-question/#findComment-1399569 Share on other sites More sharing options...
Christian F. Posted December 15, 2012 Share Posted December 15, 2012 If your script uses the GET parameter to find the city, and you haven't updated your scripts to handle the change from " " to "-", then kind of: It's not because of the .htaccess itself, but the changes you did to enable its use. In any case, you'll have to verify the received GET-parameters against what your code expects, and either make the code replace the hyphen with a space or (even better) save the new link-title in the DB and use it instead. Quote Link to comment https://forums.phpfreaks.com/topic/272007-htaccess-question/#findComment-1399586 Share on other sites More sharing options...
scm22ri Posted December 17, 2012 Author Share Posted December 17, 2012 Hey Guys, Thanks a lot for helping me out with .htaccess. It's working but for some reason my CSS isn't working? It seems the city pages aren't displaying properly. I'm not sure what the problem is, could it even be my CSS? or perhaps it's my .htaccess? What do you guys think? (state page is fine) http://whatsmyowncarworth.com/rhode_island (city pages aren't displaying my CSS) http://whatsmyowncarworth.com/rhode_island/cranston http://whatsmyowncarworth.com/rhode_island/cumberland http://whatsmyowncarworth.com/rhode_island/east_providence http://whatsmyowncarworth.com/rhode_island/east_greenwhich http://whatsmyowncarworth.com/rhode_island/exeter Quote Link to comment https://forums.phpfreaks.com/topic/272007-htaccess-question/#findComment-1399739 Share on other sites More sharing options...
Jessica Posted December 17, 2012 Share Posted December 17, 2012 <link rel="stylesheet" type="text/css" href="style.css"> You need to use the full path to the css file, since you don't have a folder called the state's name. Quote Link to comment https://forums.phpfreaks.com/topic/272007-htaccess-question/#findComment-1399740 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.