Apache Rewrite Issue

Hi,

We have apache with following directory structure:

/html/a.htm
/html/b.htm
/html/c.jsp
/html/test/d.jsp
/html/test/e.jsp

We need to give user access only to some of these files.

How can we achieve the following with rewrites:

- User enters www.domain.com and gets redirected to /html/a.htm but sees url as www.domain.com/a.htm
- User enters www.domain.com/b.htm and gets redirected to /html/b.htm but sees url as www.domain.com/b.htm
- User enters www.domain.com/d.jsp and gets redirected to /html/test/d.jsp but sees url as www.domain.com/d.jsp
- User can also enter full urls to the files mentioned above and get access to them
- User gets a Gone page if he enters www.domain.com/c.jsp, www.domain.com/e.jsp or corresponding full urls.

Please advise.

Thanks!
LVL 7
Yury MerezhkovDevelopment Team LeadAsked:
Who is Participating?
 
Yury MerezhkovDevelopment Team LeadAuthor Commented:
Hi, thanks for the reply.

I never said that html is DocumentRoot. I solved the issue using these rewrites:

RewriteRule  ^/HTML/a\.htm(.*)$ - [L,NC]
RewriteRule  ^/HTML/b\.htm(.*)$ - [L,NC]
RewriteRule  ^/HTML/test/d\.jsp(.*)$ - [L,NC]

RewriteCond %{REQUEST_URI} !^/HTML
RewriteRule ^(.*)$ /HTML\$1 [L,NC]

# If not allowed by list above - go away!  [G] is '410 Gone'
RewriteRule  .*  - [G]
# END Positive list of URLs

ErrorDocument 410 /HTML/z_page_not_found.jsp

Thank you.
0
 
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
1) www.domain.com has DocumentRoot of /html

This fixes a.htm + b.htm

2) This makes no sense...

- User enters www.domain.com/d.jsp and gets redirected to /html/test/d.jsp but sees url as www.domain.com/d.jsp

Likely you can do this... mkdir test && mv d.jsp test/d.jsp && ln -s test/d.jsp d.jsp

Now www.domain.com/d.jsp returns content from test/d.jsp

3) This doesn't make sense...

- User can also enter full urls to the files mentioned above and get access to them

The best way to reference multiple files by different names is via symlinks, as above.

Keep in mind if you return the same content for different links, the pages involved will receive a duplicate page level content penalty.

If you have to many page level content penalties (Google doesn't say how many), page level content penalty promote to full site duplicate content penalties + you're site will then be out of the index (no SEO results), in practical terms. Your site will still be there, just all SERPs will be demoted, so no one will every see them.

4) This makes no sense either...

- User gets a Gone page if he enters www.domain.com/c.jsp, www.domain.com/e.jsp or corresponding full urls.

By Gone page, I'm guessing you mean a 404 error.

To produce a 404 for c.jsp or e.jsp, remove or rename them.
0
 
Yury MerezhkovDevelopment Team LeadAuthor Commented:
Solution that works.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.