Gossamer Forum
Home : General : Perl Programming :

Help with rewrite

Quote Reply
Help with rewrite
Hello,

I have this rewrite and when I enter in the browser bar to point to a cetain page, for example : mysite.com/Los Angeles it will redirect to the cgi and produce a custom page for Los Angeles.

However, in the browser bar it will print "mysite.com/Los%20Angeles" and I want to make a couple of changes.

1) I would like for it to remove all %20 and spaces, etc., and replace them with dashes (-) and Lowercase the letters so it will show in the browser bar as mysite.com/los-angeles.
2) If I enter a directory name in the browser bar, I would like for it to point it to a script in that directory, for example: if I enter, mysite.com/mydirectory/los-angeles then it should look for cgi2.pl in the directory.

Thanks in advance.

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^$
RewriteCond %{REQUEST_URI} ![A-Z0-9]/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /cgi.pl?town=$1 [L]