0

我添加了 *.domain.com。到我的绑定,所以之后我可以运行链接到我的主页的所有子域,所以 bleble.domain.com 打开主页 domain.com

我的主要目标是使用 htaccess 将 {subdomain_name}.domain.com 链接到 /index.php?/member/{subdomain_name} 而无需重定向 301

到目前为止,我有类似的东西,但它不起作用:

RewriteEngine On
RewriteBase /

# sub domains
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
RewriteRule (.+)$ /index.php?/member/$1 [L,P]

# codeigniter
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^core.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

我收到这样的错误

Not Found
The requested URL /index.html was not found on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
4

1 回答 1

0

尝试将您的子域规则更改为:

RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
RewriteCond %{QUERY_STRING} !^/member/
RewriteRule ^(.*)$ /index.php?/member/%2/$1 [L]

你的条件是正确的,你想匹配%{HTTP_HOST}变量。对子域进行分组([a-z0-9-]+),您可以RewriteRule通过使用%2%1将引用“www.”)在您的中反向引用它。

$1反向引用是,(.*)因为您还希望能够匹配空白 URI。这样,如果您http://subdomain.domain.com/在浏览器中访问,它会在 获得内容/index.php?/member/subdomain/,如果您访问,http://subdomain.domain.com/path/to/a/file则会在 获得内容/index.php?/member/subdomain/path/to/a/file

您还想丢失P标志,因为您不需要任何代理。

于 2012-08-02T05:10:33.640 回答