URL problem

I have this http://www.website.com/dir1/dir2/dir3/file.php

I need this file.php to be displayed as http://www.website.com/dir3/file.php

Is this impossible? I don't want users to see the whole path, so redirect is out.
Who is Participating?
use this one, it's work exactly for you...
Options +FollowSymlinks
RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} !^www..*
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^([^.]*).(com|com/)
RewriteRule ^.*$ http://www.%1.%2%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_URI} /dir3/.*
RewriteRule dir3/(.*) /dir1/dir2/dir3/($1) [T=application/x-httpd-php,L]

Open in new window

Encrypt the file path
Beverley PortlockCommented:
Look at URL rewriting with the MOD_REWRITE module in apache. Basically, you set up a rule that takes your existing URL and rewrites it behind the scenes. In your example it might look like this (UNTESTED)

RewriteEngine On
RewriteRule ^/([^/]+)/(.*)$   /dir1/dir2/$1/$2

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Beverley PortlockCommented:
Actually, I should have had this

RewriteEngine On
RewriteRule ^/([^/]+)/(.*)$   /dir1/dir2/$1/$2 [L]

And here is a link to the official version  http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
Beverley PortlockCommented:
I am obviously thinking one step at a time here.... do you need to reformat the link BEFORE displaying it or do you need the capability of handling a displayed link that does not physically match the folder structure? Mod-rewrite matches the second part of that question and may be needed anyway, but I am unclear from your question whether you have already done part 1 or still need to do it.

or you can use Frames
<META NAME="description" CONTENT="WEBSITE.com">
<META NAME="keywords" CONTENT="">
<FRAMESET border=0 rows="100%,*" frameborder="no" marginleft=0 margintop=0 marginright=0 marginbottom=0>
<frame src="http://www.WEBSITE.com" scrolling=auto frameborder="no" border=0 noresize>
<frame topmargin="0" marginwidth=0 scrolling=no marginheight=0 frameborder="no" border=0 noresize>
Andrew DerseIT ManagerCommented:
Ok, stupid question here...why can't you just move the dir3 to your root level?

Instead of root/dir1/dir2/dir3/file.php...

Just put dir3 here:


Like I said, stupid question, but I thought I would ask to obvious one first as no one else has yet...
Ray PaseurCommented:
@NUKIT: Exactly! the right idea!
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.