I would like to know how to allow periods at the end on my url's. 开发者_如何学CCurrently if I had the url:
http://www.mydomain.com/Page/I.D.K.
The page grabbing the information would return
Title: I.D.K (Without the ending period)
This also happens with other punctuation and it is effecting my pages displaying information wrongly. Thanks for looking, hope somebody knows the solution.
I am using the following in my htaccess file:
RewriteRule ^([^/.]+)/?$ /index.php?Page=$1 [L]
RewriteRule ^([^/.]+)/([^/]+)/?$ /index.php?Page=$1&Level1=$2 [L]
RewriteRule ^([^/.]+)/([^/]+)/([^/]+)/?$ /index.php?Page=$1&Level1=$2&Level2=$3 [L]
RewriteRule ^([^/.]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?Page=$1&Level1=$2&Level2=$3&Level3=$4 [L]
Ok problem virtually solved. The &
still breaks my strings if I try doing Artist1 & Artist2
but I will just use string replace to replace that symbol with something else. Anyway, to allow punctuation anywhere, even at the end, I replaced all +
with *
in my rewrite rules. Here is how it looks now:
RewriteRule ^([^/.]*)/?$ /index.php?Page=$1 [L]
RewriteRule ^([^/.]*)/([^/]*)/?$ /index.php?Page=$1&Level1=$2 [L]
RewriteRule ^([^/.]*)/([^/]*)/([^/]*)/?$ /index.php?Page=$1&Level1=$2&Level2=$3 [L]
RewriteRule ^([^/.]*)/([^/]*)/([^/]*)/([^/]*)/?$ /index.php?Page=$1&Level1=$2&Level2=$3&Level3=$4 [L]
Hope this helps some other people with similar problems.
I'm assuming this is located in http://www.mydomain.com/. Here's what I'd use for the second Rule (which can then be transposed to the other rules):
RewriteRule ^([A-Za-z0-9\-,]+)/([A-Za-z0-9.\-,]+)/?$ /index.php?Page=$1&Level1=$2 [L]
That will match the following: (and will allow for hyphens, commas, and periods for Level1)
IDK/Jump.ing.
IDK/Jump.ing./
But not:
S$!LV/J
I try and whitelist my options (something like /[A-Z]/
), rather than blacklist them (/[^3-5]/
). I'm sure there are arguments for both options, but I like whitelisting mostly because I have control over what can be used. If I don't include it in my list, it's not a valid option. Of course, if you're accepting a LOT of options, then this could make for some very long character classes or whatnot. What if someone went to http://www.mydomain.com/Page/I.D.K.&somevariable=somevalue ? It could potentially break your script (if the person is smart). Your RewriteRule would send them to /index.php?Page=Page&Level1=I.D.K.&somevariable=somevalue
. Not at all what you anticipated happening.
精彩评论