rondog Posted March 19, 2009 Share Posted March 19, 2009 In an effort to make a site I am working on more search engine friendly I need to manipulate the URLs a bit. Say I have a link that looks like this: http://mysite.com/?page=optimization I would like to use mod rewrite to make it something like this: http://mysite.com/solutions/optimization How would I write that? I've googled but regular expression is beyond me at this point. Any help would be appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/150091-solved-need-help-with-mod-rewrite/ Share on other sites More sharing options...
corbin Posted March 19, 2009 Share Posted March 19, 2009 RewriteRule ^([^/])/?$ /?page=$1 Will redirect blah to ?page=blah. You could throw solutions in there if you want: RewriteRule ^solutions/([^/])/?$ /?page=$1 Quote Link to comment https://forums.phpfreaks.com/topic/150091-solved-need-help-with-mod-rewrite/#findComment-788209 Share on other sites More sharing options...
rondog Posted March 19, 2009 Author Share Posted March 19, 2009 RewriteRule ^([^/])/?$ /?page=$1 Will redirect blah to ?page=blah. You could throw solutions in there if you want: RewriteRule ^solutions/([^/])/?$ /?page=$1 I'm not really following..What exactly is ^([^/])/?$ doing? Quote Link to comment https://forums.phpfreaks.com/topic/150091-solved-need-help-with-mod-rewrite/#findComment-788214 Share on other sites More sharing options...
corbin Posted March 19, 2009 Share Posted March 19, 2009 Just noticed that ^([^/])/?$ Should be ^([^/]+)/?$ I can explain it in detail if you want, but it essentially forwards: somesites.com/blah/ to somesite.com/?page=blah Where blah is a string composed of anything but /. Quote Link to comment https://forums.phpfreaks.com/topic/150091-solved-need-help-with-mod-rewrite/#findComment-788241 Share on other sites More sharing options...
rondog Posted March 19, 2009 Author Share Posted March 19, 2009 so would I change all my links in my code from: http://mysite.com/?page=optimization to http://mysite.com/optimization or does mod rewrite do that for me? Quote Link to comment https://forums.phpfreaks.com/topic/150091-solved-need-help-with-mod-rewrite/#findComment-788946 Share on other sites More sharing options...
corbin Posted March 19, 2009 Share Posted March 19, 2009 Mod rewrite has nothing to do with HTML content or PHP pages. It simply internally (or sometimes externally) 'translates' the incoming URI to the correct thing for Apache to do. Simple answer: You have to change links your self, or just do it with a script. Quote Link to comment https://forums.phpfreaks.com/topic/150091-solved-need-help-with-mod-rewrite/#findComment-788963 Share on other sites More sharing options...
rondog Posted April 22, 2009 Author Share Posted April 22, 2009 I am trying to get this to work yet again and am having problems I have a link like this: http://mysite.com/?page=news&id=25 I want it displayed as http://mysite.com/news/25 My .htaccess file contains this. I cant get it working LoadModule rewrite_module modules/mod_rewrite.so AddModule mod_rewrite.c Options +FollowSymLinks Options +Indexes RewriteEngine On RewriteRule ^news/([0-9]+)$ ?page=news&id=$1 Quote Link to comment https://forums.phpfreaks.com/topic/150091-solved-need-help-with-mod-rewrite/#findComment-816556 Share on other sites More sharing options...
rondog Posted April 22, 2009 Author Share Posted April 22, 2009 ok I managed to get it working..for some reason my styles are not loading correctly however. Visit http://ostari.com, on the left click one of the news links that say "See More" Notice all my styles go away..what do I need to do to ensure this doesnt happen? here is my .htaccess file as of now: Options +FollowSymLinks RewriteEngine On RewriteRule ^news/([0-9]+)$ ?page=news&id=$1 Firebug is telling me my css file cant be found and its looking in /news/inc/css/main.css when really it is just /inc/css/main.css Is their a RewriteRule I can do for that? Quote Link to comment https://forums.phpfreaks.com/topic/150091-solved-need-help-with-mod-rewrite/#findComment-816704 Share on other sites More sharing options...
rondog Posted April 22, 2009 Author Share Posted April 22, 2009 if I do this: RewriteRule /inc/css/main.css http://ostari.com/inc/css/main.css it kinda works..ehh there has to be a better way.. I also tried: RewriteRule /inc/css/main.css ../inc/css/main.css which gave me a 404 not found and then tried: RewriteRule /inc/css/main.css ^../inc/css/main.css which gave me a 500 internal server error. Quote Link to comment https://forums.phpfreaks.com/topic/150091-solved-need-help-with-mod-rewrite/#findComment-816718 Share on other sites More sharing options...
rondog Posted April 22, 2009 Author Share Posted April 22, 2009 ok I figured it out! instead of writing paths like "inc/css/main.css" you use "/inc/css/main.css" sames goes for any others links to javascript, images, pages etc Quote Link to comment https://forums.phpfreaks.com/topic/150091-solved-need-help-with-mod-rewrite/#findComment-816735 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.