sirlouis
sirlouis

Reputation: 65

How can i use .htaccess to point to a directory different from the one on the url bar

am stuck trying to use .htaccess to point to the template directory for users of my site.

the directory where user is directed after login is mysite.com/lu/user1/ whereas the content i want to load is at mysite.com/lu/default/

what i want to achieve is load content from the default template directory so that i can modify the page when necessary and it will reflect on all user accounts pages.

this whole thing is to say: when a user is in mysite.com/lu/user1/ let content from mysite.com/lu/default/ be served to the user without mysite.com/lu/default/ showing on the url bar. and if the user is at mysite.com/lu/user1/settings/ or mysite.com/lu/user1/settings/?rw=yyy&uui=uuu let the served directory be mysite.com/lu/default/settings/ or mysite.com/lu/default/settings/?rw=yyy&uui=uuu

i also do not want the users to have direct access to the template directory e.g mysite.com/lu/default/

this code was posted to me but i dont know htaccess syntax

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !^/(index|excluded1|excluded2)\.php [NC]
RewriteRule ^((?!u/).+)$ u/$1 [L,NC]

thanks for ur tym.

Upvotes: 1

Views: 80

Answers (2)

anubhava
anubhava

Reputation: 785256

You can use this .htaccess inside /lu/ directory:

RewriteEngine On
RewriteBase /lu/

# block direct access to /lu/default
RewriteCond %{THE_REQUEST} /lu/default [NC]
RewriteRule ^ - [F]

RewriteRule ^([A-Z0-9]{6})/?$ profile.php?cod=$1 [L,QSA] 

# route every user/* to default/*
RewriteRule ^\w+/(.*)$ default/$1 [L,NC]

Upvotes: 1

Panama Jack
Panama Jack

Reputation: 24458

You should just be able to rewrite to the default directory. You can try this rule.

RewriteEngine On
RewriteBase /

#redirect to the home page if they request direct default directory
RewriteCond %{THE_REQUEST} {A-Z}{3,}\ /lu/default/?([^&\ ]*)
RewriteRule ^ / [R=301,L]

#internally rewrite to the default directory QSA flag will send any query string attached.
RewriteRule ^lu/(?!default)([^/]+)/?(.*?)/?$ /lu/default/$1/$2 [L,QSA]

Upvotes: 0

Related Questions