3

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

pollux1er
  • 131
  • 6

1 Answers1

5
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 ..

Jay
  • 6,439
  • 24
  • 34
  • i tried but not working – pollux1er Jul 12 '12 at 23:01
  • I've tested it and it works, so I'm standing by the answer - you might have a conflicting rule elsewhere. Can you paste your entire `.htaccess` into the question? – Jay Jul 12 '12 at 23:04
  • Ok, I read your explanation, but it is not working – pollux1er Jul 12 '12 at 23:06
  • ok let me paste it : – pollux1er Jul 12 '12 at 23:07
  • Options +FollowSymlinks RewriteEngine on RewriteRule ^/link/go/(.*)$ /process.php?email=$1 – pollux1er Jul 12 '12 at 23:07
  • There is no `^` in my answer. Please copy and paste it as-is and let me know :-) – Jay Jul 12 '12 at 23:08
  • No worries, if you could accept the answer by pressing the green hollow tick on the left, I'd appreciate it :-) – Jay Jul 12 '12 at 23:15
  • For what it's worth, here's an example of doing more robust email validation in the regex: http://www.regular-expressions.info/email.html I agree with Jay that it should be done in the PHP code though. – BenC Jul 12 '12 at 23:37
  • btw here is a good cheat sheet for mod_rewrite which can be handy. http://www.addedbytes.com/download/mod_rewrite-cheat-sheet-v2/png/ – golja Jul 12 '12 at 23:58