freemancomputer Posted December 11, 2012 Share Posted December 11, 2012 I am working on a site redesign and as part of that I want to do an url rewrite. Currently my page looks like /rules.php?title=Ax+men i would like them to look like /Ax-men. Keep in mind that the title will change and can contain letters an numbers I have done this before with numbered pages but am not sure how to adapt it to a variable length and text and numbers. This will also have to work with pagination, and with old back links that might be out there This is what I had on a different site #Options +FollowSymlinks #RewriteEngine on #RewriteRule ^(.*)\.htm$ $1.php [nc] Options +FollowSymlinks RewriteEngine on RewriteRule ^story-([0-9]+)\.html$ story.php?currentpage=$1 Mainly looking for tips and pointers Quote Link to comment https://forums.phpfreaks.com/topic/271852-url-rewrite/ Share on other sites More sharing options...
requinix Posted December 11, 2012 Share Posted December 11, 2012 (edited) It's the same as before except you have to worry about the URL conflicting with existing pages. That's why I would suggest a structure closer to /rules/Ax-men So, good news and bad news. Bad news: it's difficult to do string replacement with mod_rewrite, which you would use to turn "Ax-men" (as requested) to "Ax men" (what rules.php wants) Good news: you could just do that in rules.php As for the whole conflict thing should you stick with your original plan, the solution is a couple RewriteConds before the RewriteRule: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d Edited December 11, 2012 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/271852-url-rewrite/#findComment-1398689 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.