subdir redirect

Using mod_rewrite to handle various content issues

subdir redirect

Postby LittleBigS » Thu Feb 07, 2008 11:58 am

Hi all,

I like to redirect requests from /user_name/somefile to /somefile
i.e. /user_name/site.php?query should call /site.php?query
If just /user_name/ or /user_name is requested, it should redirect to /portal.php?lusername=user_name
Because not all subdirs are virtual I've excluded the real one

On one server the following works fine, but on another sever the redirect of /user_name/somefile to /somefile
didn't work (Error 404)
Code: Select all
RewriteEngine on
# exclude those dirs
RewriteRule ^/(cgi-bin|phpimage|topangebote|images|cadmin|ibe|cache|phpThumb|tf_intranet)/(.*)$ - [L]
# if file not exist
RewriteCond %{REQUEST_FILENAME} !-f
# two levels
RewriteRule ^/(.*)/(.*)/(.*)\.(.*)$ /$3.$4 [L]
# one level
RewriteRule ^/(.*)/(.*)\.(.*)$ /$2.$3 [L]
# do nothing on these extensions
RewriteRule ^/(.*)\.(php|gif|jpe?g|pdf|txt|html?|html|htm|js|png|ico|cfg|pl)$ - [L]
# entry redirect
RewriteRule ^/(.*)/$ /portal.php?lusername=$1 [L]
RewriteRule ^/(.*)$ /portal.php?lusername=$1 [L]


Has anyone a clue what's wrong?
LittleBigS
 
Posts: 2
Joined: Thu Feb 07, 2008 11:06 am

Postby richardk » Thu Feb 07, 2008 4:08 pm

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine on

# Exclude these directories.
RewriteRule ^(cgi-bin|phpimage|topangebote|images|cadmin|ibe|cache|phpThumb|tf_intranet)(/.*)?$ - [L]

# One and two levels.
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^[^/]+/([^/]+/)?([^/]+)$ /$2 [L]

# Entry rewrite.
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /portal.php?lusername=$1 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby LittleBigS » Thu Feb 07, 2008 11:44 pm

Thanks richardk for the fast reply, but unfortunately it didn't work.
It fails to do the redirect to /portal.php?lusername=$1 [L] which is in case some kind of login. I'm getting a 404 on /user_name.

[update]
After a little trial and error I found the solusion.
Code: Select all
RewriteEngine on

# Exclude these directories.
RewriteRule ^/(cgi-bin|phpimage|topangebote|images|cadmin|ibe|cache|phpThumb|tf_intranet)(/.*)?$ - [L]

# One and two levels.
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^/[^/]+/([^/]+/)?([^/]+)$ /$2 [L]

# Entry rewrite.
RewriteRule ^/(.*).(php|gif|jpe?g|pdf|txt|html?|html|htm|js|png|ico|cfg|pl)$ - [L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^/([^/]+)/?$ /portal.php?lusername=$1 [L]



Thank again to richardk for his support and keeping this forum a fountain of wisdom.
LittleBigS
 
Posts: 2
Joined: Thu Feb 07, 2008 11:06 am


Return to Content

Who is online

Users browsing this forum: No registered users and 3 guests

cron