phillystyle123
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 _currexima ges=$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_n ewaqimages =$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_n ewaqimages =$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
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
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_n
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_n
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?perma link=$1&Au toArtID=$2 &PageNum_n ewaqimages =$3 [QSA]
RewriteRule ^/new-editions/(.+?)/([^\/ \.]+)/?$ /new/popup-edition.cfm?Aut oArtID=$1& PageNum_ne waqimages= $2 [QSA]
RewriteRule ^/new-editions/ /new/index-edition.cfm [QSA]
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/(.+?)/(.+?)
RewriteRule ^/new-editions/(.+?)/([^\/
RewriteRule ^/new-editions/ /new/index-edition.cfm [QSA]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]
is the perfect solution for this problem
is the perfect solution for this problem
ASKER
I'm not sure what "some-handler" is in this though:
RewriteRule ^/new/(.+?)/(.+?)/([^\/\.]
RewriteRule ^/new/(.+?)/([^\/\.]+)/?$ /newaq/popup.cfm?AutoArtID
RewriteRule ^/new/([^\/\.]+)/?$ /newaq/index.cfm?PageNum_n
RewriteRule ^/new/(.*)$ /newaq/$1 [QSA]
<Location /newaq/idex.cfm>
DirectorySlash Off
SetHandler some-handler
</Location>