IIRF redirect combine rules?

1.6k views Asked by At

I have 3 "rules". One to make sure URLs are lowercase another to include a slash at the end of directories, and a 3rd to force access to index.html pages to be thru the directory instead.

The problem w/ how I have it is, sometimes this is causing multiple 301 redirects. I'd really like each rule to apply in turn and then if neccessary redirect once to the final url. For example a url might need to be converted to lowercase and have a slash added. Or may need to be lowecase and change from index.html to a directory.

Any ideas how I can do this? Thanks very much.

The rules are below:

#LOWERCASE URLS For Directories, aspx, html files
RedirectRule ^/(.*[A-Z].*(/|\.html|\.aspx))$  /#L$1#E [R=301]


#ADD SLASH TO DIRECTORIES
#---------------------------------------------
#Perm Redirect If:
#Starts w/ Forward Slash
#Match Any Characters Except (. or ?) 1 or more times
#End w/ someting besides a dot, ?, or slash
#If So, Perm Redirect captured piece W/ Slash At End and at front
RedirectRule ^/([^.?]+[^.?/])$ /$1/  [I,R=301]


#CHANGE INDEX.HTML REQUESTS TO DIRECTORY REQUESTS
#---------------------------------------------
RedirectRule ^/(.*)/index\.html$ /$1/  [I,R=301]
3

There are 3 answers

0
Gumbo On

I only see the chance to combine the latter two:

RedirectRule ^/([^A-Z?]*[A-Z].*(/|\.html|\.aspx))$  /#L$1#E [R=301]
RedirectRule ^/([^.?]+?[^.?/])(/index\.html)?$ /$1/ [I,R=301]
0
Cheeso On

There's an excellent answer to this question on the IIRF Forums.

0
Cameron Knowlton On

unfortunately, the response on the IIRF forums does not solve the multiple redirect issue. each rule still causes its own redirect.

using a RewriteRule [without a redirect flag] instead of a RedirectRule throws an error in IIRF status:

# rule:
# force HTTPS [disable on dev site until port 80 and port 443 served by same site]
# after rewrite continue with remaining tests
RewriteCond %{HTTPS}    off
RewriteRule ^/(.*)$ https://www.example.com/$1 [NC]

error: C:\Inetpub\wwwroot\example-com\www\Iirf.ini(26): WARNING: Rewriting to a fully-qualified URL. Probably wrong. You may want RedirectRule or ProxyPass.

I'd anticipated that IIRF would have taken the results of this rule and sent it back through the IIRF rules again, pickup up any other URL modifications along the way, and ultimately sending a single 301 redirect back to the browser with the final result of all rewrites. The [N] flag does this in mod_rewrite, from what I understand.