Replacing any instances of a single character

Discuss practical ways rearrange URLs using mod_rewrite.

Replacing any instances of a single character

Postby timd » Wed Feb 02, 2005 7:27 am

Ok, this is driving me nuts! I've got two problems at the moment:

I've got a whole load of requests coming in with the format:

Code: Select all
www.foo.bar/this_is_the_page.php


but the filenames are actually in the format

Code: Select all
www.foo.bar/this-is-the-page.php


So first question is how on earth I replace any and all instances of '_' with '-'

The second question is whether it's possible to trim the inbound

Code: Select all
this_is_the_page


ie everything between the last / and the first . to a maximum of 25 characters?

I'm sure they've both got to be really simple questions if you're in the know, but they're driving me nuts! :(
timd
 
Posts: 1
Joined: Wed Feb 02, 2005 7:17 am

Postby Caterham » Wed Feb 02, 2005 10:46 am

No, this is a more complex issure, because your webserver might crash (runs out of virtual memory) due to looping sub-requests under some circumstances.

see viewtopic.php?p=1618#1618

this worked at least on the testing envrionment wrote:
Code: Select all
RewriteEngine On
RewriteRule ^(.+)_(.+)\.php$ $1-$2.php [N]
RewriteRule ^(.*)-(.*)\.php$ $1-$2.php [R=301,L]



ie everything between the last / and the first . to a maximum of 25 characters?
There is no slash for http//www.foo.bar/this-is-the-page.php. mod_rewrite in a .htaccess in http//www.foo.bar/.htaccess will only see the red part of the URL
Caterham
 
Posts: 690
Joined: Fri Dec 10, 2004 1:30 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 65 guests

cron