homepage Welcome to WebmasterWorld Guest from 107.20.34.144
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Trailing slash issue with multiple parameters
Trailing slash issue
tabish

5+ Year Member



 
Msg#: 4147952 posted 4:38 am on Jun 7, 2010 (gmt 0)

Hi All,

I am again stuck with trailing slash issue, this time a little bit complicated.

This is my rewrite:

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^([a-zA-Z_]+)$ index.php?country=$1
RewriteRule ^([a-zA-Z_]+)/([a-zA-Z_]+)$ index.php?country=$1&state=$2
RewriteRule ^([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)$ index.php?country=$1&state=$2&city=$3
RewriteRule ^([a-zA-Z_]+)/([a-zA-Z_]+)/([a-zA-Z_]+)/age-([0-9\-]+)$ index.php?country=$1&state=$2&city=$3&age=$4

It works like this.. each time when a user selects country it asks for the state and then city. for example

domainname.com/country

after that

domainname.com/country/state

after that

domainname.com/country/state/city


and so on..

It works fine.. BUT when i add trailing slash, I get page not found error.

For example

domainname.com/country would work perfect

BUT

domainname.com/country/ will give error

also

domainname.com/country/state would work fine

BUT

domainname.com/country/state/

will generate error

Please help me.

Regards
Tabish

 

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4147952 posted 6:39 am on Jun 7, 2010 (gmt 0)

First off, you need to add
[L] to each rule.

Also
[a-z_] with [NC] flag will parse faster than [A-Za-z_] here. However, I would use a hyphen not an underscore in the URL.

To fix the other problem, you simply need a redirect before all of these rewrites such that if URL is requested with trailing slash, user is redirected to URL without trailing slash.

A search for "
site:webmasterworld.com remove trailing slash" will find prior examples.
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved