Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mod Rewrite - Regular Expression to include everything but slash

In my .htaccess I have a rewrite rule which reads $_GET values from a clean looking url. For one of the sections in the url I'm allowing all characters (.*) to be part of the var. The only issue with this is when I follow a link to my site from twitter, it includes a final '/ ' in the url.

RewriteRule ^advertise/([A-Za-z0-9]+)/(.*)/?$ advertise/?a=b&content=$1&content_att=$2 [L]

www.mysite.com/advertise/content/content_att works just fine
- but
www.mysite.com/advertise/content/content_att/ trys including the '/ ' as part of the content_att var. What would the expression be to only exclude slashes? (or any other mod_rewrite convention to accomplish this)

like image 956
iRector Avatar asked Jan 12 '13 04:01

iRector


1 Answers

[^/] will include any character except /
[^/]* will include any number of characters that are not /

In action should look like this:

RewriteRule ^advertise/([A-Za-z0-9]+)/([^/]+)/?$ advertise/?a=b&content=$1&content_att=$2 [L]
like image 165
CSᵠ Avatar answered Oct 25 '22 20:10

CSᵠ