Page 1 of 1

[HELP NEEDED] - Using mod_rewrite to strip chars in URL

Posted: Sat Jul 15, 2006 2:39 am
by RobertGonzalez
I have a mod_rewrite ruleset in my .htacess file and it works the way I need it to except for one thing...

When a user enters the URL http://www.mysite.com./ (see the additional '.' before the trailing slash) the ruleset passes this through and is causing problems in my script. The problem is that I am using the URL to determine which page we are on and that '.' is killing the params sent to my script. I know I can fix this code-side but I was hoping for a mod_rewrite solution.

Anyone have any ideas? As a note, the following rules are not working:

Code: Select all

#0 or more of any char
RewriteRule ^(.*)$ /index.php [QSA,L]
#1 or more of any char
RewriteRule ^(.+)$ /index.php [QSA,L]

Posted: Sat Jul 15, 2006 9:29 am
by nickvd
I could be inclined to fix it on the php side, as the trailing dot is indeed valid for the url schema.

By chance, are you using this regex to clean up your url's? I've been working on a quick and dirty class for doing exactly that, the .htaccess was lifted from the cakephp package and is working flawlessly, however i never thought to try your problem with my class, though i will as soon as i get home.

Code: Select all

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
Although I'm not 100% sure what !-d and !-f do, i'm guessing that they're ensuring that the file or directory in the url aren't valid and exist before blindly redirecting to the index. Which was the cause of major headaches for a prior project of mine, leading to a rule each for images, css, js, etc... such a PITA... heh


Sorry if i'm blabbering or not making sense, it's early and i'm running on fumes ;)

Posted: Sat Jul 15, 2006 5:45 pm
by RobertGonzalez
!-f and !-d check to make sure the file and directory do not exist before redirecting to them. I can do this on the code side, but I would really like to get it working in mod_rewrite.