Amer
Amer

Reputation: 263

Apache URL rewriting, how to serve static html file but disallow direct access to it?

I am trying to serve /help using /static/help/index.html. This does it fine:

RewriteRule ^help$ /static/help/index.html [L]

The problem is, Google is somehow double indexing both URLs, /help and /static/help/index.html. I want to 301 the .html URL. I tried adding a 301 so it looks like:

RewriteRule ^help$ /static/help/index.html [L]
RewriteRule ^static/help/index.html /help [NS,R=301,L]

I ended up with a redirection loop!

How do I tell it not to apply the second rule when used internally? NS is not doing the trick.

Upvotes: 1

Views: 724

Answers (2)

Amer
Amer

Reputation: 263

This also solved the problem:

RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^static/help/index.html /help [R=301,L]
RewriteRule ^help$ /static/help/index.html [L]

Upvotes: 0

Dusan Bajic
Dusan Bajic

Reputation: 10869

Try this:

RewriteRule ^help$ /static/help/index.html [L]
RewriteCond %{THE_REQUEST} \s/static/help/index.html
RewriteRule ^static/help/index.html /help [NS,R=301,L]

Upvotes: 1

Related Questions