如何使用的.htaccess来隐藏URL目录名称如何使用、名称、目录、URL

2023-09-02 11:27:22 作者:Nightmare°(梦魇)

下面是我的网站URL结构如下: http://www.sitename.com/new /关于美。

Here is my site url structure as follows: http://www.sitename.com/new/about-us .

我真的想现在要做的就是隐藏的目录名'新'从上面的网址,但管理URL应该保持不变。

What I really want to do now is hide the directory name 'new' from the above url, but the admin url should remain unchanged.

管理URL会是这样: http://www.sitename.com/new/admin

The admin url would be like : http://www.sitename.com/new/admin .

我的previous的.htaccess code如下:

My previous .htaccess code as follows:

  RewriteEngine On
  RewriteBase /new/

  RewriteCond %{HTTP_HOST} !^www.
  RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/new/$1 [R=301,L]

  RewriteRule blog/ - [L]
  RewriteRule (^wlp) - [L]

  RewriteRule admin/ - [L]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %(REQUEST_FILENAME} !-d
  RewriteRule ^([Ss/+.]+)/?$ index.php?url=$1 [QSA,L]

下面是我的服务器的目录结构:

Here is my server directory structure:

  /public
    /new
      .htaccess
      index.php
      about-us.php
      /blog
      /admin

任何帮助在这方面将是非常美联社preciated。

Any help in this regard will be highly appreciated.

推荐答案

这听起来像你正在试图完成什么是的常用技术这是我以前见过的转发所有的的public_html 的请求的的public_html /公共的基本上隐藏内容从用户的的public_html 的目录中,使的的public_html /公共的新的Web根目录中。

It sounds like what you are trying to accomplish is a common technique which I've seen before for forwarding all public_html requests to public_html/public to essentially hide the contents of the public_html directory from the user and making public_html/public the new web root.

尝试在你的用这个的public_html /的.htaccess 文件(你可以在的public_html /新/的.htaccess 的写进一步htaccess的):

Try using this in your public_html/.htaccess file (you can write further htaccess in public_html/new/.htaccess):

RewriteEngine on
RewriteBase /

#enforce www subdomain
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^sitename.com [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

#forward all requests, except new/admin, to the 'new' directory without the user's awareness
RewriteRule  new/admin  -  [S=2]
RewriteRule  ^$ new/    [L]
RewriteRule  (.*) new/$1 [L]