[users@httpd] Mod-Rewrite: Changing + to -, _ or .

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Someone wrote the following mod-rewrite rules for me:

RewriteEngine On
RewriteRule ^test\.htm$ test.php [L]

RewriteRule ^stacks/([a-zA-Z]+)/?$
stacks/index.php?taxon=$1 [L]
RewriteRule ^kids/stacks/([a-zA-Z]+)/?$
kids/stacks/index.php?taxon=$1 [L]
RewriteRule ^topics/([a-zA-Z+]+)/?$
topics/index.php?topic=$1 [L]
RewriteRule ^kids/topics/([a-zA-Z+]+)/?$
kids/topics/index.php?topic=$1 [L]
RewriteRule ^reference/([a-zA-Z+]+)/?$
reference/index.php?topic=$1 [L]
RewriteRule ^kids/reference/([a-zA-Z+]+)/?$
kids/reference/index.php?topic=$1 [L]

They work fine except for one problem - I don't like
URL's that look like this:

http://www.geozoo.org/topics/Temperate+Conifer+Forests

So I want to experiment with other space-filling
characters, primarily -, _ and .

http://www.geozoo.org/topics/Temperate-Conifer-Forests
http://www.geozoo.org/topics/Temperate_Conifer_Forests
http://www.geozoo.org/topics/Temperate.Conifer.Forests

But I can't figure out how to make any of these work.
For example, I can't make a URL with dashes work
whether I change RewriteRule ^topics/([a-zA-Z+]+) to
examples 1, 2 or 3 below:

1. RewriteRule ^topics/([a-zA-Z-]+)
2. RewriteRule ^topics/([a-zA-Z+]-)
3. RewriteRule ^topics/([a-zA-Z-]-)

Do I have to change something in my PHP code, too? On
one forum, someone said I shouldn't use urlencode
and/or urldecode, but I didn't understand why.

Thanks.

<?php
echo '';
while ($row = mysql_fetch_array($topic, MYSQL_ASSOC))
{

$Display2 = urlencode($row['Name']);
$Display3 = $row['Name'].$row['Name2'];
$Display3 = str_replace(' and', ' &amp;', $Display3);
$Display = '<a
href="'.$Display2.''.$row['Name2'].'">'.$Display3.'</a>
| ';

$url_name = urldecode($_GET['topic']);

$Display = rtrim($Display, '+'); 

echo <<<EOD
$Display
EOD;
}
}
echo '</div><!--EndDivIndex-->';
?>


		
__________________________________ 
Yahoo! Mail for Mobile 
Take Yahoo! Mail with you! Check email on your mobile phone. 
http://mobile.yahoo.com/learn/mail 

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux