views:

87

answers:

2

I would like to know how to allow periods at the end on my url's. Currently 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]
A: 

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.

Jeff Rupert
This did not seem to work properly. Basically a blacklist would be easier, I just want to tell it to break ONLY at a backslash, because there will be a variety of punctuation in the strings. Here are some example urls:<pre><code>www.mysite.com/Artist/Jay-Z/www.mysite.com/Artist/T.I./www.mysite.com/Artist/Lil' Wayne/www.mysite.com/Artist/3OH!3/</code></pre>So there will be a variety, including spaces and I need all that information grabbed by my code. Hope this information is enough to solve the problem. Thanks for the quick response.
Brandon
P.S. Sorry I am not sure how the formatting works on this website yet.
Brandon
http://stackoverflow.com/editing-help - That will tell you how to use Markdown for formatting. Comments cannot use straight HTML, however.
Jeff Rupert
So, let me get this straight. The first capture should get the `Page` variable, second capture is `Level1`, etc. This is all in the root of your domain? I just want to confirm so I can help better.
Jeff Rupert
Yes, that is correct. Everything goes through my index.php file. Then it grabs the "Page" which is Artist and then grabs "Level 1" which is the Artist name. Page will never contain punctuation, but level 1, level 2, etc will at some point have punctuation. Thanks again for the help
Brandon
A: 

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.

Brandon