Shinyshell Community Forums > Coding > Querystring Halp Again |
||||||
Sign Up | Member List | New Posts | Help |
[1]
September 02 02009, 21:22 GMT | ||||
Peter* A Pythonic One Location: US Post count: 99 |
I noticed something the other day. When using the previously referenced URL querystring shortener with HTACCESS (?id=pagename), http://mysite.com/pagename works but http://mysite.com/pagename/ doesn't. Is this fixable (since some people do this) or not? : ]
|
September 03 02009, 22:30 GMT | ||||
lec** Supra stultitiam Location: Varaždin, Croatia Post count: 173 |
Yes, it's easy, just add a forward slash into the regex and make it optional by using the question mark (?).
Post the regex you're using, and I can help. |
September 06 02009, 22:47 GMT | ||||
Peter* A Pythonic One Location: US Post count: 99 |
RewriteEngine on #Make it so that /index.py?id=x is /x (x = string) RewriteRule ^([A-Za-z0-9_-]+)$ index.py?id=$1 |
September 06 02009, 23:14 GMT | ||||
SpaceMan Member Location: Earth Post count: 32 |
Change the last line to RewriteRule ^([A-Za-z0-9_-]+)\/?$ index.py?id=$1 |
September 07 02009, 20:38 GMT | ||||
Faltzer Member Location: Glendale, New York Post count: 38 |
Don't be so silly, SpaceMan plus plus. You forgot to escape the underscores and dashes. Mostly the dashes, since they're interpreted as literal otherwise.
By the way, Peter, your RewriteRule is going to conflict with actual files unless you make a condition where it only uses the RewriteRule if it's not a file or a directory. Like so: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([A-Za-z0-9\_\-]+)\/?$ index.py?id=$1 Tested and works perfectly. By the way, a note on you using forward slashes at the end of your URI: If you have both, you are going to have to choose which one to give more priority to (i.e. redirect to). Otherwise, search engines will deduct you have duplicate content, which is inherently a bad thing anyway. ______________________________ FHQ |
September 07 02009, 21:37 GMT | ||||
lec** Supra stultitiam Location: Varaždin, Croatia Post count: 173 |
Faltzer said No, you're being silly. They're "interpreted as literal otherwise?". Lol. The underscore isn't a special character, and has no special meaning in bracket character classes. The hyphen has a special meaning, but not if it's at the end of the class. This holds for any regex variants I know of. And they are interpreted as literals, thank goodness. Now you mention it, the forward slash also has no special meaning. It only needs to be escaped if you used it to start and end the regular expression. |
September 07 02009, 23:42 GMT | ||||
Faltzer Member Location: Glendale, New York Post count: 38 |
said Hmm, you have proved a silly. It seems I forgot the rule that applied to the hyphens. I withdraw that portion of my statement then. ______________________________ FHQ |
November 03 02009, 23:10 GMT | ||||
Peter* A Pythonic One Location: US Post count: 99 |
Hey again.
Not so much querystring problems... this time it's .HTACCESS. I'm not too good with it and haven't taken the time to learn much more than basic things. This time I'm wanting to remove file extensions, but I don't want to interfere with my other code. .htaccess contains: ErrorDocument 404 /404.html Options +ExecCGI AddHandler cgi-script .py DirectoryIndex index.py RewriteEngine on RewriteRule ^profile/([A-Za-z0-9_-]+)/? profile.py?userid=$1 RewriteRule ^poem/([A-Za-z0-9_-]+)/? poem.py?id=$1 But I want login.py to show up as /login. ^_^ |
November 06 02009, 03:14 GMT | ||||
lec** Supra stultitiam Location: Varaždin, Croatia Post count: 173 |
I'm pretty sure this question has come up before. Have a look here: http://shinyshell.net/community/topic?id=90.
Just change the ".php" parts to ".py" of course. If you want to remove the extension for just the login.py script: RewriteRule ^login/? login.py I guess. |
November 06 02009, 21:55 GMT | ||||
Peter* A Pythonic One Location: US Post count: 99 |
Not quite what I meant. I want it to say that if the page is not otherwise defined in the htaccess file just remove the file extension.
E.G. a blanket statement over login.py, index.py, help.py. But this doesn't effect the other rules. ;) |
[1]
Forum Information |
||||||||||
|