How to use htaccess to point to a different directory?

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.

  • Answer:

    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]

slb at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

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]

Panama Jack

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.