binarywebs Posted December 5, 2010 Share Posted December 5, 2010 Hello, I am thinking of changing the structure of my CMS for future websites to produce more search engine friendly urls. Currently the urls I get are; www.mydomain.com/index.php?page=wooden-windows What I want to acheive is; www.mydomain.com/windows/wooden-windows/ I know this can be done with mod rewrite but I was thinking this may be possible to do from the get go with php? Here is what I think would be possible; Create links within the cms structure by pulling out the current pages parent e.g. www.mydomain.com/parent1/parent2/actual-page/ then when the page is requested a line of code at the top of the page uses explode to find the last / and retrieves the page as "actual-page". the next bit of code then queries the database and drags out all the info for the record with unique reference "actual-page". Does this sound like it would work properly and does any see any problems that might occur with it? Thanks Dan Quote Link to comment https://forums.phpfreaks.com/topic/220736-search-engine-friendly-urls-for-cms-without-mod-rewrite/ Share on other sites More sharing options...
Philip Posted December 5, 2010 Share Posted December 5, 2010 Sooo.... are you saying you'd eventually have a bunch of nearly empty index.php's through a bunch of directories? Quote Link to comment https://forums.phpfreaks.com/topic/220736-search-engine-friendly-urls-for-cms-without-mod-rewrite/#findComment-1143296 Share on other sites More sharing options...
binarywebs Posted December 5, 2010 Author Share Posted December 5, 2010 No I wasn't intending on doing but now you've pointed that out I suppose that would be the only way, back to the drawing board :'( In your opinion is mod rewrite the only option for achieving Search Engine (SE) friendly urls? Quote Link to comment https://forums.phpfreaks.com/topic/220736-search-engine-friendly-urls-for-cms-without-mod-rewrite/#findComment-1143317 Share on other sites More sharing options...
Philip Posted December 5, 2010 Share Posted December 5, 2010 It probably isn't the only option, but may I ask why you want to deviate away from it? Quote Link to comment https://forums.phpfreaks.com/topic/220736-search-engine-friendly-urls-for-cms-without-mod-rewrite/#findComment-1143393 Share on other sites More sharing options...
binarywebs Posted December 7, 2010 Author Share Posted December 7, 2010 I was looking at mod re-write as a cure to the problem as oppose to a fix so was thinking starting from scratch maybe it could be done from php. I think maybe I was over complicating the situation though. Thanks for putting me back on the right track, I think this is the mod re-write I would need to use to get my desired urls? Options +FollowSymlinks RewriteEngine on RewriteRule ^([^/]+)/([^/]+)/([^/]+).php /index.php?page=$3&parent1=$1&parent2=$2 [NC] Maybe after some further research I could complete this with some if statements for if parent1 or parent2 is not set Quote Link to comment https://forums.phpfreaks.com/topic/220736-search-engine-friendly-urls-for-cms-without-mod-rewrite/#findComment-1143904 Share on other sites More sharing options...
Philip Posted December 8, 2010 Share Posted December 8, 2010 You could compact that down a bit. I'll see if I can post an example when I can keep my eyes open for more than 30 seconds Quote Link to comment https://forums.phpfreaks.com/topic/220736-search-engine-friendly-urls-for-cms-without-mod-rewrite/#findComment-1144260 Share on other sites More sharing options...
Adam Posted December 10, 2010 Share Posted December 10, 2010 You could always resort to passing parameters through the 'PATH_INFO' server var: example.com/index.php/parent1/parent2/actual-page Just doesn't look as good. Quote Link to comment https://forums.phpfreaks.com/topic/220736-search-engine-friendly-urls-for-cms-without-mod-rewrite/#findComment-1145379 Share on other sites More sharing options...
Anti-Moronic Posted December 13, 2010 Share Posted December 13, 2010 I was looking at mod re-write as a cure to the problem as oppose to a fix so was thinking starting from scratch maybe it could be done from php. I think maybe I was over complicating the situation though. Thanks for putting me back on the right track, I think this is the mod re-write I would need to use to get my desired urls? Options +FollowSymlinks RewriteEngine on RewriteRule ^([^/]+)/([^/]+)/([^/]+).php /index.php?page=$3&parent1=$1&parent2=$2 [NC] Maybe after some further research I could complete this with some if statements for if parent1 or parent2 is not set Problem with this is if you want to add a new parent, you have to update the match. What if your 20 nested deep? The desired way is to route everything to a front controller (with exception of some resources like images etc), and then your frontcontroller will parse the url. That way you can keep all your logic and variable management in php. Try to download Zend or Wordpress to see how they manage this. Simple htaccess file has: RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L] Then you use parse_url() in your app to manage the variables (i.e. 'parent1' above). Quote Link to comment https://forums.phpfreaks.com/topic/220736-search-engine-friendly-urls-for-cms-without-mod-rewrite/#findComment-1146770 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.