man5 Posted March 20, 2014 Share Posted March 20, 2014 I have question regarding the setup of url for multiple pages. For eg. How does one have a setup like this? http://www.groupon.ca/deals/gatineau_en/Antirouille-Metropolitain/35853918 The setup I have is like this. //Page 1 with posts shown in a specific catagory. www.mysite.ca/posts_cat.php?catagoryId=1 //Page 2 with a single post shown. www.mysite.ca/posts.php?title=this is my post As you can see, my url setup is quite different than Groupon's. I am not sure if it's the correct way to do it; but it does work. The reason I have two different pages for posts are because I have two different css designs. I suppose my question is, is my method ok? And how do I make it so it looks like Groupon's way? Quote Link to comment https://forums.phpfreaks.com/topic/287125-a-new-question-regarding-multiple-pages-links/ Share on other sites More sharing options...
Ch0cu3r Posted March 20, 2014 Share Posted March 20, 2014 Yes those types of urls are possible when using mod_rewrite Quote Link to comment https://forums.phpfreaks.com/topic/287125-a-new-question-regarding-multiple-pages-links/#findComment-1473360 Share on other sites More sharing options...
man5 Posted March 20, 2014 Author Share Posted March 20, 2014 Great. That's what I was looking for. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/287125-a-new-question-regarding-multiple-pages-links/#findComment-1473366 Share on other sites More sharing options...
man5 Posted March 20, 2014 Author Share Posted March 20, 2014 Alright so I am trying to modify the url with mod_rewrite in .htaccess. Here is an example. Tell me if it's wrong. localhost/demo/post.php?title=my post title here RewriteRule ^post/([^/\.]+)/?$ post.php?title=$1 [L] If it's correct, it doesn't seem to work. Quote Link to comment https://forums.phpfreaks.com/topic/287125-a-new-question-regarding-multiple-pages-links/#findComment-1473384 Share on other sites More sharing options...
Ch0cu3r Posted March 21, 2014 Share Posted March 21, 2014 You need to make sure you are outputting your urls like <a href="http://localhost/demo/post/my post title here">my post title here</a> not as <a href="http://localhost/demo/post.php?title=my post title here">my post title here</a> Quote Link to comment https://forums.phpfreaks.com/topic/287125-a-new-question-regarding-multiple-pages-links/#findComment-1473436 Share on other sites More sharing options...
man5 Posted March 22, 2014 Author Share Posted March 22, 2014 (edited) sorry for the late reply. I tried to figure this out on my own, so far so luck. The urls I have are actually directory based. Like this. <a href="posts.php?title=my post title here">Post one</a> Can you please show me the rewrite code that outputs the above to what you mentioned? And here is my .htaccess file. RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule .* - [L] Thanks. Edited March 22, 2014 by man5 Quote Link to comment https://forums.phpfreaks.com/topic/287125-a-new-question-regarding-multiple-pages-links/#findComment-1473535 Share on other sites More sharing options...
kicken Posted March 22, 2014 Share Posted March 22, 2014 (edited) Can you please show me the rewrite code that outputs the above to what you mentioned? That's not what mod_rewrite is for. You need to update your web pages yourself to output your friendly URL so the HTML source code received by the browser actually reads as <a href="/demo/post/my post title here">my post title here</a> mod_rewrite will then translate that back to your un-friendly url of /demo/posts.php?title=my+post+title+here If you don't update your code to output the friendly URLs in the first place, the the whole mod_rewrite setup is mostly pointless. Edited March 22, 2014 by kicken Quote Link to comment https://forums.phpfreaks.com/topic/287125-a-new-question-regarding-multiple-pages-links/#findComment-1473538 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.