Htaccess email regex

.htaccesspattern matchingregex

I am trying to write a patter in such a way that this link :

http://www.mysite.com/link/go/emailadress@gmail.com

is interpreted like this :

http://www.mysite.com/process.php?email=emailadress@gmail.com

But i dont know how to write. I tryied this but it is not working. Need help please.

This what I wrote in my .htaccess file but not working :

Options +FollowSymlinks
RewriteEngine on 
RewriteRule    ^link/go/overview/([A-Za-z0-9-]+)$    /process.php?email=$1    [NC,L]

Thanks

Best Answer

RewriteRule link/go/(.*)$ process.php?email=$1

This seems to work. You should do the email validation in process.php, not in the .htaccess rule for the sake of readability (plus, you can at least have a nice error message on the page).

This works because anything after link/go/ will be matched (. matches any character, so .* means match any character as many times as it can, and (.*) means save this into $1 - The $ at the end means end of line, so it'll match all the way to the end).

What you tried won't work because [A-Za-z0-9-]+ will only match letters and numbers, no @ or ..

Related Topic