JesseToxik Posted June 9, 2013 Share Posted June 9, 2013 hey all, In honesty I have looked at tutorials for creating "pretty links" and I can honestly say I do not understand how to use it. I am using a navigation system that includes requested files using a URL like http://mysite.com?page=home. What I would like to do is make the links appear as http://mysite.com/page/home. How can I achieve this? I am not asking for the code to be written for me, just help in the right direction. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/278965-not-understanding-mod_rewrite/ Share on other sites More sharing options...
JesseToxik Posted June 9, 2013 Author Share Posted June 9, 2013 This is my .htaccess file. ErrorDocument 404 http://google.com // Google just to test it RewriteEngine On RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [L] #LoadModule rewrite_module modules/mod_rewrite.so #AddModule mod_rewrite.c RewriteRule ^page/([0-9]{4})$ /index.php?page=$1 [L] Quote Link to comment https://forums.phpfreaks.com/topic/278965-not-understanding-mod_rewrite/#findComment-1435008 Share on other sites More sharing options...
kicken Posted June 9, 2013 Share Posted June 9, 2013 RewriteRule ^page/([a-z0-9]+)$ /index.php?page=$1 [L]That would match your /page/home example and translate it into /index.php?page=home. As far has making it look like /page/home in the browser, you just need to type in the URL that way. When you create your links you need to create them using the new friendly format, not the older query-string format. <a href="/page/home">Go Home</a>not <a href="/index.php?page=home">Go Home</a> Quote Link to comment https://forums.phpfreaks.com/topic/278965-not-understanding-mod_rewrite/#findComment-1435014 Share on other sites More sharing options...
JesseToxik Posted June 9, 2013 Author Share Posted June 9, 2013 I tried adding what you suggested to my .htaccess and it didnt work. This is what I have. ErrorDocument 404 http://mysite.com/404.php RewriteEngine On RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [L] #LoadModule rewrite_module modules/mod_rewrite.so #AddModule mod_rewrite.c RewriteRule ^page/([a-z0-9]+)$ /index.php?page=$1 [L] Quote Link to comment https://forums.phpfreaks.com/topic/278965-not-understanding-mod_rewrite/#findComment-1435018 Share on other sites More sharing options...
kicken Posted June 9, 2013 Share Posted June 9, 2013 Your first RewriteRule RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [L]is going to match the /pages/home url first and send the request over to /pages/home.php. You need to either disable that rule or change their orders so the other one matches first. Quote Link to comment https://forums.phpfreaks.com/topic/278965-not-understanding-mod_rewrite/#findComment-1435045 Share on other sites More sharing options...
JesseToxik Posted June 10, 2013 Author Share Posted June 10, 2013 Ok I got that to work. Whats odd is my style sheet is now not loading. http://cronanpilotcar.byethost33.com/page/home Quote Link to comment https://forums.phpfreaks.com/topic/278965-not-understanding-mod_rewrite/#findComment-1435133 Share on other sites More sharing options...
JesseToxik Posted June 10, 2013 Author Share Posted June 10, 2013 Ah I figured it out. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/278965-not-understanding-mod_rewrite/#findComment-1435134 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.