Fadion Posted October 14, 2007 Share Posted October 14, 2007 I know this is not the correct section, but i saw that the mod_rewrite secion of apache doesnt get too many hits and i need to fix this thing quick :S Im trying to make my urls search engine friendly, but im having problems. My urls look like: 1. http://www.domain.com/index.php?g=a 2. http://www.domain.com/index.php?g=a&artist=Someone 3. http://www.domain.com/index.php?g=a&artist=Someone&song=Something I made three rules for each specific combination: RewriteRule index/(.*).html /index.php?g=$1 RewriteRule index/(.*)/(.*).html /index.php?g=$1&artist=$2 RewriteRule index/(.*)/(.*)/(.*).html /index.php?g=$1&artist=$2&song=$3 The first rule is working as when i go to a url like "www.domain.com/index/a.html" it shows the correct stuff, but the other two rules dont show anything. Tried what i was able to do, but no success. Another problem is that when i go in a url like "www.domain.com/index/a.html" the styles, images and stuff dont show. I have them in specified folders in root and are called relatively, so this SEF thing is breaking the links. I could go and make every link absolute but that would be a not so cool method, so i though there's something better. Im pretty new to this so any help would be appriciated. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/73252-solved-sef-uris-problem/ Share on other sites More sharing options...
Fadion Posted October 15, 2007 Author Share Posted October 15, 2007 I realised that my first rule: "RewriteRule ^index/(.*).html$ /index.php?g=$1" stopped the other rules from working correctly. Meaning that when i type a url "index/a.html" it works ok, but when i type "index/someone/file.html" it get "someone/file.html" as a single variable for my first rule. I have another question. I have all my links generated with php which point to not SEF urls, like "index.php?g=a". With my basic understanding, i thought those urls would be translated automatically to SEF which normaly isnt happening. Do i have to modify the script to show urls like "index/a/something/anything/"? Quote Link to comment https://forums.phpfreaks.com/topic/73252-solved-sef-uris-problem/#findComment-369572 Share on other sites More sharing options...
jellis Posted October 15, 2007 Share Posted October 15, 2007 I realised that my first rule: "RewriteRule ^index/(.*).html$ /index.php?g=$1" stopped the other rules from working correctly. Meaning that when i type a url "index/a.html" it works ok, but when i type "index/someone/file.html" it get "someone/file.html" as a single variable for my first rule. I have another question. I have all my links generated with php which point to not SEF urls, like "index.php?g=a". With my basic understanding, i thought those urls would be translated automatically to SEF which normaly isnt happening. Do i have to modify the script to show urls like "index/a/something/anything/"? That's correct. You will have to modify the scripts to rewrite those URL's. The "old" URL's will still be valid as it's not requiring the .htaccess file to do any rewriting and it will be parsed as a normal URL... might I suggest that you actually set something up in a config file to enable the URL's to still be generated in the non-SEF format with the flick of a hypothetical switch? This way, if you ever move servers and they don't support .htaccess (which is a performance sacrificing ability) you will be able to re-enable non-SEF URL's. Quote Link to comment https://forums.phpfreaks.com/topic/73252-solved-sef-uris-problem/#findComment-369671 Share on other sites More sharing options...
Fadion Posted October 15, 2007 Author Share Posted October 15, 2007 After a lot of reading and experimenting, finally i achieved what i wanted. The three rules i have now are: RewriteRule ^([^/]+)\.html$ /index.php?g=$1 [L] RewriteRule ^([^/]+)/([^/]+)\.html$ /index.php?g=$1&artist=$2 [L] RewriteRule ^([^/]+)/([^/]+)/([^/]+)\.html$ /index.php?g=$1&artist=$2&song=$3 [L] I had the regex "(.*)" initally which was blocking the other rules. I modified it with "([^/]+)" which will bypass the rule if there is any "/" in the url. I had also the problem of the rewritten urls of styles and images. Tried to exclude them with RewriteCond but didnt work. Finally i realised that adding a slash before them (ex: "/styles.css" instead of "styles.css") did the trick. Now its working like a charm. @jellis, thnx for the reply. Didnt have any idea about mod_rewrite, but now i have things a bit more clear. I understand that i have to modify the script, but it isnt very much a problem. Your suggestion of having SEF and not-SEF friendly urls is a good idea. I have to think how to easily do it, but i think its easy enough. Hope these help someone who has the same problems. Quote Link to comment https://forums.phpfreaks.com/topic/73252-solved-sef-uris-problem/#findComment-370017 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.