Forum Moderators: phranque

Message Too Old, No Replies

Need Help With Mod Rewrite Replacing Spaces

         

lcp03o

7:33 pm on Jun 15, 2005 (gmt 0)

10+ Year Member



Hi, This is what is currently in my .htaccess file

RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]+\-)(.*)$ showthread.php?t=$1 [L]

This now means that I can go to www.domain.com/1234- and my page displays correctly. Now what I want to do is add the page title after the - like this "www.domain.com/1234-Thread title here" but when I put spaces in this text it reads like this "www.domain.com/1234-Thread%20title%20here"

Is there a simple way to edit the .htaccess to replace spaces with underscores _ ?

Thanks

jdMorgan

11:24 pm on Jun 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



lcp03o,

Welcome to WebmasterWorld!

It's possible, but highly-inefficient. It's slow enough that I cannot recommend it for SEO purposes. It's only useful to 'correct' a few bad links to your site, not for something that's going to run on every request.

I'd suggest you modify your scripts to output hyphens (using the PHP preg_replace directive, for example) in on-page links, and also to accept those hyphens on incoming requests, and change them back to spaces (if you even need that data once the request is being processed).

Just to be clear, mod_rewrite acts after an HTTP request is received by your server, and before any content-handlers are invoked. Therefore, it can be used to redirect to a new URL, or to cause the server to serve content from a page or script not directly-related to the requested URL. Mod_rewrite cannot change any links on your pages as they being output to the requesting client.

The best place to fix this kind of problem is in your scripts.

Jim