Replacing characters in URL

Discuss practical ways rearrange URLs using mod_rewrite.

Replacing characters in URL

Postby RLivsey » Tue Jul 20, 2004 6:57 am

I have an application which converts spaces in URLs to plusses.
A load of files on the server have spaces in their filenames (this is out of my hands) and so the URLs the application makes are wrong.

eg:
http://www.example.com/this is a file.html
comes out like:
http://www.example.com/this+is+a+file.html

The application is also out of my control so I can't change how that works, so Im stuck looking for a solution.

Is there anyway to rewrite the 2nd URL to convert the plusses back to spaces? The number of words in each filename is not fixed and varies from 0 to about 5 words.

Ive had a good look around and can't find any examples of this kind of problem.

My alternative is to make a custom 404 handler and rewrite the URLs to redirect the user. But mod_rewrite seems like a cleaner solution to the problem.

Thanks in advance
RLivsey
 

Postby Caterham » Fri Dec 10, 2004 1:51 pm

Try this one:
Code: Select all
RewriteEngine On
RewriteRule ^(.+)\+(.+) $1\ $2 [N]
RewriteRule ^(.+)\ (.+) $1\ $2 [R=301,L]
:D
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 42 guests

cron