【问题标题】:Rewrite wildcard subdomain to the same name folder and get the subdomain name重写通配符子域到同名文件夹并获取子域名
【发布时间】:2015-08-27 17:20:39
【问题描述】:

我想做下一个

subdomain.domain.com 必须加载 www.domain.com/app/index.php?var=subdomain subdomain.domain.com/index.php?var2=x 必须加载 www.domain.com/app/index.php?var=subdomain&var2=x

我有下一个加载应用程序文件夹的代码,但我也想获取子域的名称,但我不知道该怎么做。

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{HTTP_HOST} ^(\w+)\.example\.com$
RewriteCond %{REQUEST_URI}:%1 !^/([^/]+)/([^:]*):\1
RewriteRule ^(.*)$ /%1/$1 [QSA]

提前致谢。

这是我所有的 .htaccess

<Files .htaccess> 
deny from all 
</Files> 
#ModPagespeed off
# charset
AddCharset utf-8 .html
AddCharset utf-8 .js
AddCharset utf-8 .css
AddCharset utf-8 .php

# enable expirations
<IfModule mod_expires.c>
#ExpiresActive On
#ExpiresByType image/jpg "access plus 1 week"
#ExpiresByType image/jpeg "access plus 1 week"
#ExpiresByType image/gif "access plus 1 month"
#ExpiresByType image/png "access plus 1 month"
#ExpiresByType text/css "access plus 1 week"
#ExpiresByType application/pdf "access plus 1 month"
#ExpiresByType text/x-javascript "access plus 1 week"
#ExpiresByType image/x-icon "access plus 1 year"
#ExpiresDefault "access plus 1 week"
</IfModule>

<IfModule mod_deflate.c>
#AddOutputFilterByType DEFLATE text/plain
#AddOutputFilterByType DEFLATE text/html
#AddOutputFilterByType DEFLATE text/xml
#AddOutputFilterByType DEFLATE text/css
#AddOutputFilterByType DEFLATE text/js
#AddOutputFilterByType DEFLATE application/xml
#AddOutputFilterByType DEFLATE application/xhtml+xml
#AddOutputFilterByType DEFLATE application/rss+xml
#AddOutputFilterByType DEFLATE application/x-javascript

# LE INDICAMOS PARA QUE NAVEGADORES NO DEBE COMPRIMIR YA QUE PRESENTAN BUGS

#BrowserMatch ^Mozilla/4 gzip-only-text/html
#BrowserMatch ^Mozilla/4.0[678] no-gzip
#BrowserMatch bMSIE !no-gzip !gzip-only-text/html

</IfModule>

Options +FollowSymLinks
RewriteEngine on

#fuerza el acceso https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

#Wildcards del dominio

RewriteCond %{HTTP_HOST} !=www.domain.com
RewriteCond %{HTTP_HOST} ^(\w+)\.domain\.com
RewriteRule .* /app/index.php?var=%1 [QSA]

#para error personalizado
ErrorDocument 403 "No disponible"

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
AddHandler application/x-httpd-php .html .htm .shtml .js
AddType application/x-httpd-php .html .htm .js

DirectoryIndex index.php index.html

【问题讨论】:

    标签: apache .htaccess mod-rewrite configuration subdirectory


    【解决方案1】:

    这应该添加带有子域值的var 变量:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} !=www.example.com
    RewriteCond %{HTTP_HOST} ^(\w+)\.example\.com
    RewriteRule .* /add/index.php?var=%1 [QSA]
    

    【讨论】:

    • 您好,我已尝试使用您的代码,但收到内部服务器错误。
    • 我已经检查过了,它对我有用。 “Internal server Error”通常表示.htaccess中的语法错误显示您的完整文件。
    • 嗨@umka,我已将我所有的 .htaccess 添加到问题中
    猜你喜欢
    • 2021-11-14
    • 2021-05-08
    • 2017-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-02
    相关资源
    最近更新 更多