Mod ReWrite Issue. Trailing Slash Causing Issues
Posted: Tue Sep 15, 2009 1:09 pm
Hey,
I needed to take a dynamic url, such as
visit.php?user=jimmy&prod_id=5
and turn it into:
http://www.domain.com/jimmy/5
This allows sales merchants to promote a product that we can track referrals for without a clunky url with querystrings/etc.
Well, I was able to do that. The only problem, though, is that if the '5' at the end of the url has a trailing slash, such as:
http://www.domain.com/jimmy/5/ --> the '404 not found page' loads up instead of redirecting to the merchant url.
Without the trailing slash, it works fine. I have no complaints UNLESS it is a / ending in the url.
How do I allow the following code in my .htaccess to allow a trailing slash without giving the 404 page errors?
Thank you very much for your time.
I needed to take a dynamic url, such as
visit.php?user=jimmy&prod_id=5
and turn it into:
http://www.domain.com/jimmy/5
This allows sales merchants to promote a product that we can track referrals for without a clunky url with querystrings/etc.
Well, I was able to do that. The only problem, though, is that if the '5' at the end of the url has a trailing slash, such as:
http://www.domain.com/jimmy/5/ --> the '404 not found page' loads up instead of redirecting to the merchant url.
Without the trailing slash, it works fine. I have no complaints UNLESS it is a / ending in the url.
How do I allow the following code in my .htaccess to allow a trailing slash without giving the 404 page errors?
Code: Select all
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(exe|css|js|jpeg|jpg|gif|html|php|ttf|png)$
RewriteRule ^([^/]+)/([^/]+)$ /visit.php?prod_id=$1&aff_id=$2&page=$3
ErrorDocument 404 /404.php