简体   繁体   中英

Dynamically redirect to subfolder using .htaccess, hide subfolder in url without using domain name

I have a subfolder I want to redirect to, I want it to redirect dynamically so anytime I go to:

example.domain/about it takes me to example.domain/subfolder/about , but still shows: example.domain/about in the address bar

However, I don't want to have to specify a domain name so I can use it in any project. So I suppose just automatically want to declare the root domain name as a variable?


I have this working here:

RewriteRule !^subfolder/ /subfolder%{REQUEST_URI} [L,R=301]

And it doesn't require the domain name, but it still shows subfolder in the domain name.


The strategy in this answer is what I need, but minus the domain name:

RewriteEngine On
RewriteRule ^/subfolder/(.*)$ http://www.example.domain/$1 [L,R=301]

I also need it to work for both the www. and the naked domain.

Try the following rule :

RewriteEngine On
#remov php exten
RewriteCond %{DOCUMENT_ROOT}/subfolder/$1.php -f
RewriteRule ^(.*)$ /subfolder%{REQUEST_URI}.php [NC,L]
#redirect root to sub
RewriteRule ^((?!subfolder).*) /subfolder%{REQUEST_URI} [L,NC]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM