.htaccess - quietly rewrite / redirect everything to an internal subfolder

Let's say I have a site structure www.example.com:

/srv/http/
/srv/http/site/index.php
/srv/http/site/stuff.php

I want the following rewrites / redirects to occur:

www.example.com/index.php→ redirects to → www.example.com/site/index.php→, but the user sees →www.example.com/index.php

www.example.com/stuff.php→ redirects to → www.example.com/site/stuff.php→, but the user sees →www.example.com/stuff.php

In general, everything after is www.example.com/redirected to www.example.com/site/. But the user sees the source URL in the browser.

I looked on the Internet, but could not figure out what to use in this particular situation.

I tried to rewrite everything:

RewriteEngine On
RewriteRule ^$ /site [L]

but index.phpdisappears, and the user is displayed www.example.com/site/.

How can I use .htaccessto solve this problem?

+4
source share
3

url, , :

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/site/
RewriteRule ^(.*)$ /site/$1 [L,QSA]

QSA ( ) URL

+7

, @guido,

RewriteEngine On
RewriteRule ^(?!site/)(.*)$ site/$1 [L]

. QSA, URL- . Apache URL- .

http://www.example.com/index.php?one=1&two=2 

http://www.example.com/site/index.php?one=1&two=2

(ex: mode=rewrite) , QSA Query String Append

RewriteEngine On
RewriteRule ^(?!site/)(.*)$ site/$1?mode=rewrite [L,QSA]

mode=rewrite

http://www.example.com/index.php?one=1&two=2 

http://www.example.com/site/index.php?mode=rewrite&one=1&two=2 
+5
RewriteEngine On

RewriteRule ^(.*)$ site/index.php?var=$1 [L]

With this rule, I pass all requests to the /index.php site, so you can get the requested uri through $ _GET ['var'], and then you will do index.php to request the URL behind the scene, without changing the URL in a custom browser. Ciao.

+1
source

All Articles