fohanlon Posted July 25, 2011 Share Posted July 25, 2011 Hi Guys Trying to get my head around a mod_rewrite I am doing. I found plenty on the web re this question but no definitive answer. Here is what I have to do. I have a link to a page called content.php?id=123&name=SOME NAME HERE where id ties back to the 123 for pageid and name is what I want to use for Search Engine Optimisation. So here is what I have so far: RewriteRule ^([^/]*)/([^/]*)$ /content.php?id=$1&name=$2 [L] But what I want to do - only show the name in the url at the top Instead of www.somedomain.com/123/SOME NAME HERE I want www.somedomain.com/SOME NAME HERE but still need to use the id to pull back the page content to be displayed. Can anyone suggest how to change the rule above? Hope this makes sense and its the right place to post this. Many thanks Fergal. Quote Link to comment https://forums.phpfreaks.com/topic/242797-mod_rewrite/ Share on other sites More sharing options...
requinix Posted July 26, 2011 Share Posted July 26, 2011 You can't. Make content.php find id according to that name (if it actually needs the ID number), which will be really hard if those names aren't unique. Quote Link to comment https://forums.phpfreaks.com/topic/242797-mod_rewrite/#findComment-1247085 Share on other sites More sharing options...
cags Posted July 26, 2011 Share Posted July 26, 2011 The only way of doing it without an id number is by generating unique slugs based on the name. A common way of doing this is simply replacing non-url safe characters with a hypen, checking if it's unique and then incrementing a counter on the end in cases where it isn't, until you find a unique slug. Alternatively, due to the fairly small chance of you getting the same name on the same day, a lot of people use a date structure in their URL, such as /2011/07/26/my-title-here. The basic idea boils down to the same thing though, you need a value unique for that 'article' that you can query the database for. Once you have that you can bang a unique index on it to make searching quicker and Roberts your aunties brother. Quote Link to comment https://forums.phpfreaks.com/topic/242797-mod_rewrite/#findComment-1247146 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.