Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Is this URL masking?

Posted on 2006-03-22
13
Medium Priority
?
205 Views
Last Modified: 2008-03-17
For the sake of organisation I would like to keep all my content in one directory on the server

http://domain.com/content/apple/
http://domain.com/content/banana/

but I would like the browser to display

http://domain.com/apple/
http://domain.com/banana/

Is this possible?

Sandy
0
Comment
Question by:SandyCooke
  • 7
  • 6
13 Comments
 
LVL 27

Expert Comment

by:caterham_www
ID: 16256482
If you call /banana/ you should get the page from /content/banana/, so it should not be visible that your pages served from /content/? That can be done with mod_rewrite in a .htaccess file

RewriteEngine on
# rewrite a request of /apple/ --internally to--> /content/apple/
RewriteRule ^([^/.]+)/$ /content/$1 [L]

I'm not sure, if the regular expression fits all your needs, bot it would match on your example.
0
 
LVL 2

Author Comment

by:SandyCooke
ID: 16264769
Thanks for the help but with the above code a request for

http://domain.com/apple/

is redirecting to

http://domain.com/content/apple/

but the browser address is also changing to

http://domain.com/content/apple/

which I would like to avoid...

?

p.s. does # denote a comment in Apache? I am a tru newb!
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 16264997
> but the browser address is also changing to

That is not normal behaviour. Only if you add the R-Flag or prefix the substitution with scheme+host, an external redirection would occour from mod_rewrite. Do you have the RedirctMatch in place? That would/might cause an additional problem, too.

RewriteEngine on
# the same RedirectMatch does
RewriteCond %{THE_REQUEST} /content/
RewriteRule ^content/(.*) /$1 [R=301,L]
# rewrite a request of /apple/ --internally to--> /content/apple/
RewriteRule ^([^/.]+)/$ /content/$1 [L]

If there's still a redirect, the only way to analyzing it would be a rewrite log, because this is not normal behaviour.

> does # denote a comment in Apache?

yes.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:SandyCooke
ID: 16284800
@ caterham_www

I am trying to combine the fruits of your recent help into one .htaccess file

This works as desired:

----------------------------------------------------------

# legacy redirect:

RedirectMatch 301 ^/legacydir/(.*) http://mydomain.com/$1

RewriteEngine on

# add trailing slash to avoid browser adding "www"

RewriteCond %{REQUEST_URI} !/$
RewriteRule !\.[a-z]{2,5}$ - [C]
RewriteRule ^(.+) http://%{HTTP_HOST}/$1/ [R=301,L]

------------------------------------------------------

BUT

I would additionally like a request for

http://domain.com/banana/

to "secretly" serve the content of

http://domain.com/fruit/banana/

SO

I have added

RewriteRule ^([^/.]+)/$ /fruit/$1 [L]

at the bottom of the file

BUT

this just redirects as mentioned above (the browser address changes)

SO

I replaced this line with

# RewriteEngine already on
RewriteCond %{THE_REQUEST} /fruit/
RewriteRule ^ fruit/(.*) /$1 [R=301,L]
RewriteRule ^([^/.]+)/$ /fruit/$1 [L]

and I get a 500 error presumably because (if I understand you correctly) the RedirectMatch at the top of the file is interfering with this bit

RewriteCond %{THE_REQUEST} /fruit/
RewriteRule ^ fruit/(.*) /$1 [R=301,L]

?

0
 
LVL 27

Expert Comment

by:caterham_www
ID: 16285079
RewriteRule ^ fruit/(.*) /$1 [R=301,L]
             ^^^^^
there is a space where no space should be: between ^  and fruit/

^fruit/


> the RedirectMatch at the top of the file is interfering with this bit

Those two lines are a replacement for RedirectMatch
0
 
LVL 2

Author Comment

by:SandyCooke
ID: 16285393
Still no joy - when I request

http://domain.com/banana/

Safari gives me the error:

Too many redirects occurred trying to open “http://www.domain.com/fruit/banana/”. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page.

The whole .htaccess file is below:

--------------------------------------

# legacy redirect

RedirectMatch 301 ^/legacydir/(.*) http://domain.com/$1

RewriteEngine on

# add trailing slash to request if missing to avoid browser adding "www"

RewriteCond %{REQUEST_URI} !/$
RewriteRule !\.[a-z]{2,5}$ - [C]
RewriteRule ^(.+) http://%{HTTP_HOST}/$1/ [R=301,L]

# internally serve request for http://domain.com/banana/ with content from directory http://domain.com/fruit/banana/

# RewriteEngine already on
RewriteCond %{THE_REQUEST} /fruit/
RewriteRule ^fruit/(.*) /$1 [R=301,L]
RewriteRule ^([^/.]+)/$ /fruit/$1 [L]
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 16285644
Ah, I see the problem. The last line must be

RewriteRule ^([^/.]+/)$ /fruit/$1 [L]
0
 
LVL 2

Author Comment

by:SandyCooke
ID: 16285730
Thank you for your tireless assistance but now a request for

http://domain.com/banana/

is correctly loading the index page of

http://domain.com/fruit/banana/

but all the links in that index page

<IMG SRC="banana.jpg" etc.

are Not Found because the browser is trying to load

http://domain.com/banana/banana.jpg

while the image is actually at

http://domain.com/fruit/banana/banana.jpg

?
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 16285781
two ways to resolve it: instead of the last rule:

RewriteCond $1 !^fruit
RewriteRule ^([^/.]+/.*)$ /fruit/$1 [L]

to rewrite all other ressources, too.
Or you're using absolute paths src="/fruit/banana/banana.jpg"
0
 
LVL 2

Author Comment

by:SandyCooke
ID: 16285887
Is it possible to exclude certain requests from this rule?

For instance I would like a request for

http://domain.com/myxmlfile.xml

to load

http://domain.com/myxmlfile.xml

not

http://domain.com/fruit/myxmlfile.xml

?

P.S. When you say "instead of the last rule" does "the last rule" mean all of

RewriteCond %{THE_REQUEST} /fruit/
RewriteRule ^fruit/(.*) /$1 [R=301,L]
RewriteRule ^([^/.]+)/$ /fruit/$1 [L]
0
 
LVL 27

Accepted Solution

by:
caterham_www earned 2000 total points
ID: 16286089
> P.S. When you say "instead of the last rule" does "the last rule" mean all of

no, only the last line.

> Is it possible to exclude certain requests from this rule?

Yes, but /myxmlfile.xml should not be affected by the rules, only /folder/myxmlfile.xml would be affected. The RegEx would match only, if a folder (slash) is present.
To exclude other folders

RewriteCond $1 !^(fruit|other-folder)
RewriteRule ^([^/.]+/.*)$ /fruit/$1 [L]
0
 
LVL 2

Author Comment

by:SandyCooke
ID: 16286705
You are a star! Thank you for your patience, it works like a charm!
0
 
LVL 2

Author Comment

by:SandyCooke
ID: 16286711
p.s. the fruits of your labour are at

http://golo.co.uk/
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question