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
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

Edited by requinix
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.