troubleshooting Question

Apache/Mod_Rewrite: Redirect and Rewrite without Loop

Avatar of hankknight
hankknightFlag for Canada asked on
Apache Web Server
1 Comment1 Solution406 ViewsLast Modified:
I want to redirect all pages that have ".html" as the extension to NOT have the ".html" extension and I want to rewrite all pages that do NOT have an extension to point to the page with the ".html" extension.  The problem is that my code creates a loop so does not work.

How can I get this to work without creating a loop?

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_fileNAME} -f
RewriteRule ^(.*)\.html$ $1 [L,R=301]

RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
rewriterule ^(([^/]+/)*[^./]+)/?$ /$1.html [L]
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros