Calculated File check?

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 3
Joined: 02 Dec 2013, 18:29

Calculated File check?

02 Dec 2013, 18:37

They keep asking me to put in 'vanity' URLs where say someone typed in 'contact-us' it would go to the 'contact-us.html' page.

I would love to just have this work for all pages where it simply checks:

- Does the file exist?, simply load the page.
- Does the file with the added '.html' extension exist?, then load it (combine it with the first check?)
- Then continue with any additional rules...

Possible?

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Calculated File check?

03 Dec 2013, 00:58

Peace of cake:

Code: Select all
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME}.asp !-f
RewriteCond %{REQUEST_FILENAME}.asp !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.*) $1.html [NC,L]


Which line by line would mean:

Is it a file? no
Is it a directory? no
If we add .html is it a file? yes
Rewrite to html file with the same name as requested URL


Regards
Andrew

User avatar
Posts: 3
Joined: 02 Dec 2013, 18:29

Re: Calculated File check?

03 Dec 2013, 03:44

Thanks, It seems all too straight forward. Appreciate it!

I questioned the need for he first two Conditons and just ended up putting this at the end of the file which seems to work as you indicated.

Code: Select all
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.*) $1.html [R,L]


Just removed the NC as we're just looking for any character and want to rewrite the URL.

Is there ever a concern with doing too many 'file related' rules? Another reason to leave the first two out?

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Calculated File check?

03 Dec 2013, 08:02

I wouldn't say that there's a concern about it. However, when a list of rules grows, the chance of getting a conflict rises.

Regards
Andrew

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 0 guests