Trailing slash issue on IIS8.5
4 posts
• Page 1 of 1
Trailing slash issue on IIS8.5
Hi, I'm moving some sites from IIS6 to IIS8.5 and have a problem with extensionless .asp files that have the same root name as an existing directory, for example:
We have a file /legal-services.asp and a folder /legal-services/ containing some other files.
We're stripping the extensions from .asp requests so that /legal-services is internally rewritten to /legal-services.asp. This works fine in IIS6, but on IIS8.5 the url /legal-services has a trailing slash added before ISAPI Rewrite processes. Hence we see the error message "The Web server is configured to not list the contents of this directory." which is true.
Is there a way to prevent /legal-services being converted to /legal-services/ so that ISAPI Rewrite can do the internal redirect and not treat it as a directory?
Here's my ruleset:
RewriteEngine on
#301 redirect non-www version to www version
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301]
#Redirect extension requests
RewriteRule ^([^?]+)\.asp$ $1 [NC,R=301]
#Internally add extensions to request
RewriteCond %{REQUEST_FILENAME}.asp -f
RewriteRule (.*) $1.asp
Here are some Rewrite logs for access to the URL /legal-services
IIS6 (works fine):
(2) init rewrite engine with requested uri /legal-services
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request e:\data_area\websites\testsite\wwwroot\.roaccess
(3) applying pattern '.?' to uri 'legal-services'
(4) RewriteCond: input='off' pattern='(on)?' => matched
(4) RewriteCond: input='www.test.dev' pattern='^(?!www\.)(.+)$' => not-matched
(3) applying pattern '^([^?]+)\.asp$' to uri 'legal-services'
(3) applying pattern '(.*)' to uri 'legal-services'
(4) RewriteCond: input='E:/Data_Area/Websites/testsite/wwwroot/legal-services.asp' pattern='-f' => matched
(1) Rewrite URL to >> /legal-services.asp
(2) rewrite 'legal-services' -> '/legal-services.asp'
(2) internal redirect with /legal-services.asp [INTERNAL REDIRECT]
IIS8.5 (fails - tries to access directory)
(2) init rewrite engine with requested uri /legal-services/ <======= *** trailing slash here ***
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request c:\domains\testsite\wwwroot\.htaccess
(3) applying pattern '.?' to uri 'legal-services/'
(4) RewriteCond: input='off' pattern='(on)?' => matched
(4) RewriteCond: input='www.test.app' pattern='^(?!www\.)(.+)$' => not-matched
(3) applying pattern '^events/([0-9]+)/(.+)$' to uri 'legal-services/'
(3) applying pattern '^events/([0-9]+)$' to uri 'legal-services/'
(3) applying pattern '^([^?]+)\.asp$' to uri 'legal-services/'
(3) applying pattern '(.*)' to uri 'legal-services/'
(4) RewriteCond: input='c:\Domains\testsite\wwwroot\legal-services\.asp' pattern='-f' => not-matched
I've tried quite a few things but none have worked. Hope someone can help me get going again until I can refactor the applications.
Thanks
Ian.
We have a file /legal-services.asp and a folder /legal-services/ containing some other files.
We're stripping the extensions from .asp requests so that /legal-services is internally rewritten to /legal-services.asp. This works fine in IIS6, but on IIS8.5 the url /legal-services has a trailing slash added before ISAPI Rewrite processes. Hence we see the error message "The Web server is configured to not list the contents of this directory." which is true.
Is there a way to prevent /legal-services being converted to /legal-services/ so that ISAPI Rewrite can do the internal redirect and not treat it as a directory?
Here's my ruleset:
RewriteEngine on
#301 redirect non-www version to www version
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301]
#Redirect extension requests
RewriteRule ^([^?]+)\.asp$ $1 [NC,R=301]
#Internally add extensions to request
RewriteCond %{REQUEST_FILENAME}.asp -f
RewriteRule (.*) $1.asp
Here are some Rewrite logs for access to the URL /legal-services
IIS6 (works fine):
(2) init rewrite engine with requested uri /legal-services
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request e:\data_area\websites\testsite\wwwroot\.roaccess
(3) applying pattern '.?' to uri 'legal-services'
(4) RewriteCond: input='off' pattern='(on)?' => matched
(4) RewriteCond: input='www.test.dev' pattern='^(?!www\.)(.+)$' => not-matched
(3) applying pattern '^([^?]+)\.asp$' to uri 'legal-services'
(3) applying pattern '(.*)' to uri 'legal-services'
(4) RewriteCond: input='E:/Data_Area/Websites/testsite/wwwroot/legal-services.asp' pattern='-f' => matched
(1) Rewrite URL to >> /legal-services.asp
(2) rewrite 'legal-services' -> '/legal-services.asp'
(2) internal redirect with /legal-services.asp [INTERNAL REDIRECT]
IIS8.5 (fails - tries to access directory)
(2) init rewrite engine with requested uri /legal-services/ <======= *** trailing slash here ***
(1) Htaccess process request C:\Program Files\Helicon\ISAPI_Rewrite3\httpd.conf
(1) Htaccess process request c:\domains\testsite\wwwroot\.htaccess
(3) applying pattern '.?' to uri 'legal-services/'
(4) RewriteCond: input='off' pattern='(on)?' => matched
(4) RewriteCond: input='www.test.app' pattern='^(?!www\.)(.+)$' => not-matched
(3) applying pattern '^events/([0-9]+)/(.+)$' to uri 'legal-services/'
(3) applying pattern '^events/([0-9]+)$' to uri 'legal-services/'
(3) applying pattern '^([^?]+)\.asp$' to uri 'legal-services/'
(3) applying pattern '(.*)' to uri 'legal-services/'
(4) RewriteCond: input='c:\Domains\testsite\wwwroot\legal-services\.asp' pattern='-f' => not-matched
I've tried quite a few things but none have worked. Hope someone can help me get going again until I can refactor the applications.
Thanks
Ian.
Re: Trailing slash issue on IIS8.5
Hello, Ian
If you don't need them anywhere else, please consider disabling Extensionless URLs feature in IIS.
If you don't need them anywhere else, please consider disabling Extensionless URLs feature in IIS.
Re: Trailing slash issue on IIS8.5
Thanks Anton,
If I understand correctly, the way to do this on IIS8 is to remove the HTTP Redirection Role. However I've done that and it hasn't made any difference.
No matter what I try, I cannot prevent IIS from automatically adding the "courtesy trailing slash" when a directory exists with the same name as an extensionless .asp file.
I hope someone can help; I have rather a few applications using this structure!
Many thanks,
Ian.
If I understand correctly, the way to do this on IIS8 is to remove the HTTP Redirection Role. However I've done that and it hasn't made any difference.
No matter what I try, I cannot prevent IIS from automatically adding the "courtesy trailing slash" when a directory exists with the same name as an extensionless .asp file.
I hope someone can help; I have rather a few applications using this structure!
Many thanks,
Ian.
Re: Trailing slash issue on IIS8.5
Hello, Ian
Here's one option which might work for you and not require disabling Extensionless URLs:
RewriteRule ^(.*)eurl\.axd/.* $1 [NC,R=301,L]
Here's one option which might work for you and not require disabling Extensionless URLs:
RewriteRule ^(.*)eurl\.axd/.* $1 [NC,R=301,L]
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 14 guests