Link to home
Start Free TrialLog in
Avatar of phillystyle123
phillystyle123Flag for United States of America

asked on

htaccess rewrite rule - optional trailing slash

my client has requested that a URL work regardless of whether or not there is a trailing slash

i've updated my htaccess file and my rewrites are getting this accomplished:

for example this:
http://ikonltd.com/current/
and this:
http://ikonltd.com/current
both go to the same page

here's my rewrite rule for that:

RewriteRule ^/current/([^\/\.]+)/?$ /current/index.cfm?PageNum_curreximages=$1 [QSA]

works great.

for some reason my rewrite for this URL is different:

http://ikonltd.com/new/

and this:
http://ikonltd.com/new

does not work.

here's my rewrite for that:

RewriteRule ^/new/([^\/\.]+)/?$ /newaq/index.cfm?PageNum_newaqimages=$1 [QSA]
RewriteRule ^/new/(.*) /newaq/$1 [QSA]

it has something to do with this last bit:
RewriteRule ^/new/(.*) /newaq/$1 [QSA] (which i'm not using anywhere else in my htaccess - just for the newaq section.

you'd think if i deleted it and just used this:
RewriteRule ^/new/([^\/\.]+)/?$ /newaq/index.cfm?PageNum_newaqimages=$1 [QSA]

it'd work but it does not.

again - i need both of these urls to resolve to the same page:
http://ikonltd.com/new/
http://ikonltd.com/new
SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of phillystyle123

ASKER

I definitely want the option to to go with or without the directory slash.

I'm not sure what "some-handler" is in this though:

RewriteRule ^/new/(.+?)/(.+?)/([^\/\.]+)/?$ /newaq/newacq_detail.cfm?permalink=$1&AutoArtID=$2&PageNum_newaqimages=$3 [QSA]
RewriteRule ^/new/(.+?)/([^\/\.]+)/?$ /newaq/popup.cfm?AutoArtID=$1&PageNum_newaqimages=$2 [QSA]
RewriteRule ^/new/([^\/\.]+)/?$ /newaq/index.cfm?PageNum_newaqimages=$1 [QSA]
RewriteRule ^/new/(.*)$ /newaq/$1 [QSA]
<Location /newaq/idex.cfm>
DirectorySlash Off
SetHandler some-handler
</Location>
i managed to create a scenario where in new and new/ both resolve to the correct page - i just created an actual new directory on the server.

now, i need to adjust my .htaccess file so

http://ikonltd.com/new-editions  (no trailing slash)
resolves to the same page as
http://ikonltd.com/new-editions/ (trailing slash)

currently i just get a page not found when attempting to go to
http://ikonltd.com/new-editions  (no trailing slash)

my .htaccess code thus far:
RewriteRule ^/new-editions/(.+?)/(.+?)/([^\/\.]+)/?$ /new/newacq_detail-edition.cfm?permalink=$1&AutoArtID=$2&PageNum_newaqimages=$3 [QSA]
RewriteRule ^/new-editions/(.+?)/([^\/\.]+)/?$ /new/popup-edition.cfm?AutoArtID=$1&PageNum_newaqimages=$2 [QSA]
RewriteRule ^/new-editions/ /new/index-edition.cfm [QSA]
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]

is the perfect solution for this problem