开发者

.htaccess and url rewriting challenge

开发者 https://www.devze.com 2023-04-10 10:41 出处:网络
My problem is very simple. I have sever开发者_StackOverflow中文版al folders in my root: [folder1]

My problem is very simple.

I have sever开发者_StackOverflow中文版al folders in my root:

[folder1]
[folder2]
[folder3]

And my domain is something like: http://johndoe.net

I keep my website in [folder1], so basically I access it by typing http://johndoe.net/folder1

My goal is this:

I want to type http://johndoe.net and I get the content of http://johndoe.net/folder1 but the address has to remain http://johndoe.net

I want to type http://johndoe.net/folder1 and see my website, but my address has to change to http://johndoe.net

Seems easy enough, but I failed finding the solution after several hours of searching.

So far, the only thing I achieved is redirecting from http://johndoe.net to http://johndoe.net/folder1 by placing this bit of code in my .htaccess in my root:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^johndoe\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.johndoe\.net$
RewriteRule ^/?$ "http\:\/\/johndoe\.net\/folder1\/" [R=301,L]

When I type http://johndoe.net, I get http://johndoe.net/folder1 in my address bar

but what I need is my address to remain http://johndoe.net

Could anyone help me with this?


You're going to use two .htaccess files to solve this problem. Here's what you put in them, and where they go.

File #1. This goes in your base folder (the one that contains [folder1],[folder2], etc)

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^((www\.)?johndoe.net)$ 
RewriteRule ^(.*)$ /folder1/$1 [L]

File #2. This goes in [folder1]

RewriteEngine Off


Try something like this

RewriteRule ^(.*)$ /folder1/$1 [R=301,L]


RewriteEngine on
RewriteCond %{HTTP_HOST} ^johndoe\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.johndoe\.net$
RewriteRule ^/?$ "\/folder1\/" [L]

you need internal rewrite, So it's enough to rewrite / to /folder1/

0

精彩评论

暂无评论...
验证码 换一张
取 消