URL Directory Hiding

Discuss practical ways rearrange URLs using mod_rewrite.

URL Directory Hiding

Postby Kay » Fri Jul 25, 2008 4:27 am

Hello!

I am new to mod_rewrite and I want to use it for a new website which seriously needs some typical security.

The site url is something like http://example.teipir.gr and all main site files are in a folder called STATIC - thus for example if someone tries to find the services.html file then the url string would show.

http://example.teipir.gr/STATIC/en/services.html [for the english version]
and
http://example.teipir.gr/STATIC/gr/services.html [for the greek version]

I want to rewrite the above into something simpler like:


thus hide STATIC and covering my site's structure.

I would like this to be covered in any link inside the page's content - otherwise it would be unnecessary. Could you help me out please?
Kay
 
Posts: 5
Joined: Fri Jul 25, 2008 4:15 am

Postby richardk » Fri Jul 25, 2008 3:27 pm

The mod_rewrite would be
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Add missing trailing slashes.
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/STATIC%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Rewrite to /STATIC
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /STATIC/$1 [QSA,L]


I would like this to be covered in any link inside the page's content - otherwise it would be unnecessary.

Mod_rewrite does not change the URLs in the source of the pages.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Kay » Mon Jul 28, 2008 3:10 am

Hello Richardk and thanks for your initial support. I really appreciate this.

I just copy pasted your code in my Apache httpd file - but the effect is unexpected...

Image

It doesn't show my index.html page but the directory itself - and all access to any subpage is out of the question - as the "Not Found" page shows up. What could be going wrong? Could you help point this out?

I managed to write a code myself as well which should do the trick but it doesn't seem to work either...Check this if you please and tell me as well - whats the wrong thing in your code and in mine...

The following will display contents of http://example.com/STATIC/en/index.html when visitors browse to http://example.com/en/index.html (while maintaining http://example.com/en/index.php in the address bar of the browser)
Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /STATIC/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index.html
RewriteRule (.*) /index.html/$1 [L]
RewriteRule ^$ /$1 [L]
</IfModule>
Kay
 
Posts: 5
Joined: Fri Jul 25, 2008 4:15 am

Postby Kay » Mon Jul 28, 2008 7:15 am

To make things clearer maybe...

1) I have an .htaccess file in my document root folder.

2) I tried something simple like the redirection below and it worked.

Code: Select all
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^STATIC/en/([a-z]+)\.html$ /en/$1.html [R=301,L]


Thus this means my configuration is OK.

The only thing I want to do is just HIDE the folder in which all my SITE resides from the ADDRESS bar.
Code: Select all
My site's structure is like this:

index.html -> STATIC -> en [OR] gr -> file.html

STATIC is a folder in my site's structure and it contains another 2 folders 'EN' and 'GR' which contain the files for viewing in 2 different versions.


1) Initially the user is pointed to index.html page. Then the user can navigate to any page in the site.
2) If the user goes for example to people.html (english version) the address bar WITHOUT REWRITING should write: http://example.com/STATIC/en/people.html

3) What I need to accomplish is just hide STATIC from the above - thus when a user goes to people.html (english version) the address bar should write AFTER REWRITE: http://example.com/en/people.html


BUT NO DATA WILL HAVE BEEN MOVED TO A NEW FOLDER.
THE ORIGINAL DATA STAYS INSIDE THE /STATIC/ FOLDER.


Hope I set things right this time...

P.S. I use APACHE 2.0.63 (Win32)
Kay
 
Posts: 5
Joined: Fri Jul 25, 2008 4:15 am

Postby richardk » Tue Jul 29, 2008 11:44 am

Patience?

Try
Code: Select all
Options +FollowSymLinks
DirectoryIndex index.html index.php

RewriteEngine On

# Add missing trailing slashes.
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/STATIC%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Rewrite to /STATIC
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /STATIC/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Kay » Wed Jul 30, 2008 12:16 am

Hello richardk and thanks for your assistance.

Unfortunately this doesn't work for me either. I managed to perform the task by using
Code: Select all
AliasMatch ^/en(.*) X:/WWW/MYSITE/STATIC/en$1
and
AliasMatch ^/gr(.*) X:/WWW/MYSITE/STATIC/gr$1


and editing any link in every page of my site but i still wanna know if this is possible through MOD_REWRITE.
Kay
 
Posts: 5
Joined: Fri Jul 25, 2008 4:15 am

Postby richardk » Wed Jul 30, 2008 3:55 pm

You still have to edit all the links with mod_rewrite.

Try
Code: Select all
Options +FollowSymLinks
DirectoryIndex index.html index.php

RewriteEngine On

# Add missing trailing slashes.
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/STATIC%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Rewrite to /STATIC
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^((en|gr)(/.*)?)$ /STATIC/$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 56 guests

cron