Shinyshell Community Forums > Coding >
Querystring Halp Again


[1]


September 02 02009, 21:22 GMT
Peter*
A Pythonic One

Peter's avatar
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

lec's avatar
Location: Varaždin, Croatia
Post count: 173
hr
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

Peter's avatar
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
 
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

SpaceMan's avatar
Location: Earth
Post count: 32
ca

Change the last line to
 RewriteRule ^([A-Za-z0-9_-]+)\/?$ index.py?id=$1
 
RewriteRule ^([A-Za-z0-9_-]+)\/?$ index.py?id=$1
]]>

September 07 02009, 20:38 GMT
Faltzer
Member

Faltzer's avatar
Location: Glendale, New York
Post count: 38
us
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
 
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

lec's avatar
Location: Varaždin, Croatia
Post count: 173
hr
Faltzer said

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.


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

Faltzer's avatar
Location: Glendale, New York
Post count: 38
us
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.


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

Peter's avatar
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
 
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

lec's avatar
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
RewriteRule ^login/? login.py]]>

I guess.

November 06 02009, 21:55 GMT
Peter*
A Pythonic One

Peter's avatar
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
  Currently Active Members [detailed] (0 members and ? guests)
-
Forum Statistics
Topics: 0, Posts: 0, Members: 108.
Welcome to our newest member, adamthephantump
Most members online was 5, on August 28 2009, at 21:49:28.
Legend
    Forums with unread topics in them are indicated by a strong yellow colouring around the forum icon.
    Forums with no unread topics have the standard pale yellow colouring around the forum icon.
    Forums with a blue arrow icon will redirect you to a non-forum page.
    Locked forums have a little padlock by their icon. You won't be able to post in these forums.
Shinyshell Home | Contact | Staff List | Archive | Top 

Conventional Login

Don't have an account? You may want to create one.

OpenID Login
OpenID login and registration is usable, but not finished.
What is OpenID?
Search

(advanced search)
Site Stats
  Total members: 108
  Latest member: adamthephantump
  Members currently online: 0
  Most online: 5 - Aug 28, 2009 (21:49)
  Front page hits: 87998
Developer info
  Site version: 3.5 Alpha
  16 queries - 9 templates
Under the Spotlight
Collide Site
Collide make fabulously dreamy electronic-industrial music, they're one of my favourite bands! Give them a chance to take control of your life - myspace | youtube - "Euphoria".

Collide Site - Hits: 4596

5/5 (2) | Rate this site?