【问题标题】:Accessing the index file in public_html from SubDir从 SubDir 访问 public_html 中的索引文件
【发布时间】:2023-03-23 22:06:01
【问题描述】:

我有一个带有“.htaccess”文件的子目录,我想要的是当这个文件收到请求时,根目录中的索引执行而不改变文件中的位置..

子目录位置:'public_html/subdomains/news'

我写了'.htaccess'文件如下

 RewriteEngine on

 RewriteCond %{HTTP_HOST} ^news\.example\.com$ [OR]

 RewriteCond %{HTTP_HOST} ^www\.news\.example\.com$

 RewriteRule ^/?$  ../../index.php?url=news [L,QSA,NC]

但没用

由于这个subDir属于一个subDomain,我不希望它的地址改变,我希望用户访问位置地址:

 http://www.example.com/news

通过调用地址:

 http://news.example.com

他们没有看到

【问题讨论】:

    标签: php apache .htaccess mod-rewrite subdomain


    【解决方案1】:

    对于任何子域请求,使用这个:

    RewriteEngine on 
    RewriteCond %{HTTP_HOST} !^www\.example\.s\.co 
    RewriteCond %{HTTP_HOST} ^(.*)\.example\.s\.co 
    RewriteCond %{REQUEST_URI} !^/([a-zA-Z0-9-z\-]+) 
    RewriteRule ^(.*)$ /%1/$1 [L] 
    

    【讨论】:

      【解决方案2】:

      您需要创建一个子域并将该子域指向文件夹。

      like news.exmaple.com 将指向 public_html/news(其中 news 是文件夹名称)

      无需在 .htaccess 文件中做任何事情。

      【讨论】:

      • 我创建了子域并有权访问:news.example.com 我希望调用以下位置,而用户不会看到位置更改及其访问权限:example.com/news
      • 试试RewriteEngine On RewriteRule ^(.*)?$ ./subdomains/sub/$1
      猜你喜欢
      • 1970-01-01
      • 2015-01-01
      • 2013-01-18
      • 1970-01-01
      • 2016-10-04
      • 2014-02-03
      • 1970-01-01
      • 2016-04-30
      • 2014-06-04
      相关资源
      最近更新 更多