Hi all, I'm new of regexps, but after a consistent number of tries I've found the way to do the basics.
However I still have problems to cover all the main cases.
I don't have problems in this cases:
http://www.mysite.com/section/Value+page
I use this to do the rewrite rule:
RewriteEngine on
RewriteRule ^section_name/([a-zA-Z0-9:punct:]*)$ section_name/page.php?id=$1
now i can insert all i want but i can't avoid malicius calls like this
section_name/page.php?id=Value+page
I've saw in the site LastFM (http://www.last.fm) a good use of regexp but I haven't found a way to do the same.
in facts, if i write http://www.last.fm/user/index.php?id=username the rewrite engine search for the username "index.php?id=username"
in my rule if i do it, the page return me an error and don't force the url to the right way
Can someone explain where I'm wrong?
I thought the expression section_name/([a-zA-Z0-9:punct:]*) means all i digit in the url after the string "section_name/".
thanks
Vitto
Protect your page location
Moderator: General Moderators
- ridgerunner
- Forum Contributor
- Posts: 214
- Joined: Sun Jul 05, 2009 10:39 pm
- Location: SLC, UT
Re: Protect your page location
First off, your regex: "[a-zA-Z0-9:punct:]*" as posted, is incorrect. The ":punct:" portion (the POSIX "punctuation" character class) must be enclosed in square brackets like so: "[a-zA-Z0-9[:punct:]]". Thus, the regex you intended to write is actually: "^section_name/([a-zA-Z0-9[:punct:]]*)$"
The [:punct:] character class includes a whole lot of characters that I don't think you want to allow, including the path '/' delimiter. The [:punct:] character class is the same as this: "[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]". Thus, your original rewrite rule is effectively this:
I doubt that you intended to allow all those characters!
Second, your english grammar in your post is not very good! (I assume english is not your primary language.) And you have not provided enough information for us to help you. You need to provide some example text which clearly defines string patterns you wish to match and those that should not match.
When writing a regular expression, you need to think carefully about exactly what you want to match and exactly what you don't want to match, and then thoroughly test your final regex. I recommend that you spend some more time and learn the basics. Here is a good place to start:
http://www.regular-expressions.info/
Good luck!
The [:punct:] character class includes a whole lot of characters that I don't think you want to allow, including the path '/' delimiter. The [:punct:] character class is the same as this: "[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]". Thus, your original rewrite rule is effectively this:
Code: Select all
RewriteRule ^section_name/([a-zA-Z0-9!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]*)$ section_name/page.php?id=$1Second, your english grammar in your post is not very good! (I assume english is not your primary language.) And you have not provided enough information for us to help you. You need to provide some example text which clearly defines string patterns you wish to match and those that should not match.
When writing a regular expression, you need to think carefully about exactly what you want to match and exactly what you don't want to match, and then thoroughly test your final regex. I recommend that you spend some more time and learn the basics. Here is a good place to start:
http://www.regular-expressions.info/
Good luck!