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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Yury MerezhkovDevelopment Team LeadAuthor Commented:
Solution that works.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
mod_rewrite

From novice to tech pro — start learning today.