Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess是否从文件夹中检索子域,而不是301重定向?_.htaccess_Mod Rewrite_Subdomain - Fatal编程技术网

.htaccess是否从文件夹中检索子域,而不是301重定向?

.htaccess是否从文件夹中检索子域,而不是301重定向?,.htaccess,mod-rewrite,subdomain,.htaccess,Mod Rewrite,Subdomain,如果请求是子域,我希望我的站点只指向/user文件夹 如果请求为subdomain.site.com/admin,则站点应显示subdomain.site.com/user/admin页面 我的代码的问题是它进行了301重定向,而不仅仅是保留url地址 我的代码如下所示: <IfModule mod_rewrite.c> DirectoryIndex index.php RewriteEngine on RewriteBase / RewriteCond %{HTTP_HOS

如果请求是子域,我希望我的站点只指向/user文件夹

如果请求为subdomain.site.com/admin,则站点应显示subdomain.site.com/user/admin页面

我的代码的问题是它进行了301重定向,而不仅仅是保留url地址

我的代码如下所示:

<IfModule mod_rewrite.c>

DirectoryIndex index.php

RewriteEngine on
RewriteBase / 

RewriteCond %{HTTP_HOST} !^www.bildsida.se(.*)
RewriteCond %{HTTP_HOST} ^[^.]+.bildsida.se(.*)

RewriteRule ^$ user/$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule (.*) user/$1 [L]

</IfModule>

DirectoryIndex.php
重新启动发动机
重写基/
重写cond%{HTTP_HOST}^www.bildsida.se(**)
RewriteCond%{HTTP_HOST}^[^.]+.bildsida.se(.*)
重写规则^$user/$1[QSA,L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则(.*)用户/$1[L]

您可以自己尝试,转到并查看地址如何更改为/user/admin。非常令人不安…

您只需要几行代码就可以让它正常工作

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^www.bildsida.se
RewriteCond %{HTTP_HOST} ^.+\.bildsida\.se

RewriteRule ^(.*)$ user/$1 [L]

我调整了HTTP_主机检查,因为该参数只查看域名,所以最后不需要(.*)。我还删除了检查文件是否存在或是否是目录的检查,因为您希望所有内容都被重定向(例如,没有理由可以从其他子域访问文件)

您的代码可以简化为以下几行:(改为尝试)


终于!经过日日夜夜的阅读论坛和文档,并测试了所有可能的方法,我终于成功了

Sulotion:

<IfModule mod_rewrite.c>

    DirectoryIndex index.php

    RewriteEngine on
    RewriteBase /

    RewriteCond %{HTTP_HOST} !^www.bildsida.se
    RewriteCond %{HTTP_HOST} !^bildsida.se

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^$ user/index.php [L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)? user/$1/ [QSA]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule /(.+)/ user/$1 [QSA]

</IfModule>

DirectoryIndex.php
重新启动发动机
重写基/
重写cond%{HTTP_HOST}^www.bildsida.se
重写cond%{HTTP_HOST}^比尔德西达东南部
重写cond%{REQUEST_FILENAME}-F
重写规则^$user/index.php[L]
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
是否重写规则^(.*)?用户/$1/[QSA]
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则/(.+)/user/$1[QSA]

我现在收到“内部服务器错误”。可能是什么问题?仍然存在“内部服务器错误”:/如果您直接访问文件(在用户中),您是否存在内部服务器错误或它是否工作正常?不,我仍然存在“内部服务器错误”,那么您应该检查代码,内部服务器错误可能不是来自htaccessBut,除了重定向之外,我在问题中的代码工作正常。值得注意的是,它实际上可以输入精确的路径,如“mickes.bildsida.se/admin/index.php”。该地址获取/user/admin/index.php,即使没有/index.php,也应该这样做。
<IfModule mod_rewrite.c>

    DirectoryIndex index.php

    RewriteEngine on
    RewriteBase /

    RewriteCond %{HTTP_HOST} !^www.bildsida.se
    RewriteCond %{HTTP_HOST} !^bildsida.se

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^$ user/index.php [L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)? user/$1/ [QSA]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule /(.+)/ user/$1 [QSA]

</IfModule>