Forum Moderators: coopster

Message Too Old, No Replies

Php %20 URL character replacement with dashes

php, dreamweaver, URL characters

         

JayDev

9:32 pm on Dec 10, 2004 (gmt 0)

10+ Year Member



Hello everyone,

I am trying to figure out how to replace %20 in my URL strings which are generated in my URLs.

I have read several posts and it seems that I need to change the script in my php pages. I use php and MySQL.

Do I need to insert urldecode? or something else?

I first thought I could use a RewriteCond by it seems to not be the case. Any feedback and help on how to get rid of this %20 and replace it with - in my urls would be fantastic.

Thank you in advance.

ergophobe

9:53 pm on Dec 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$url = str_replace('%20', '-', $url);

But what's your plan for making that url valid? In other words

"my file.php" becomes encoded as "my%20file.php" which you now rename to "my-file.php" which doesn't exist on your server. You can't use mod_rewrite to rewrite "my-file.php" back to "my file.php" because you will then break every link to every file that actually has a hyphen in the name.

JayDev

1:18 pm on Dec 11, 2004 (gmt 0)

10+ Year Member



What do you mean by "which doesn't exist on your server."?

What I need to get is not my actual php page but the rest of the url to replace with "-".

for example: my-page.php?category=Interior%20Decorating

would become

my-page.php?category=interior-decorating

Then I would use .htaccess to rewrite the pages if possible.

Is there a simpler way to replace %20 with "-" using RewriteCond for example?

ergophobe

1:33 am on Dec 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I thought you were using it to change actually file references. Given your example, though, I'm still not sure why you want to replace the %20 with a -

Anyway, I'm not sure whether you can make mod_rewrite replace all occurrences of a character with something else.

JayDev

2:11 am on Dec 13, 2004 (gmt 0)

10+ Year Member



I slightly modified my tables so that the space is now replaced with - in my tables.

This is no longer a problem. I just worked around it I guess.

However, my htaccess file is not doing anything. First I tried it and got a 500 error. I went into the conf file of apache and activated the mod_rewrite module. Then I was able to view my php pages.

However, the .htaccess file is not doing anything. My urls are still in php in the url browser and nothing changed.

I placed the .htaccess file in localhost/mysite.

Here is my .htaccess file:

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(.*)\.html$ /mypage.php?addition2=$1 [L]

I also tried:

Options +FollowSymlinks
RewriteBase /
RewriteEngine On
RewriteRule ^(.*)\.html$ /mypage.php?addition2=$1 [L]

Thank you for the help:)