Jump to content

Url Rewrite


freemancomputer

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/271852-url-rewrite/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/271852-url-rewrite/#findComment-1398689
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.