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? 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 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! 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. 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> 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 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. 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 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. 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
Archived
This topic is now archived and is closed to further replies.