URL中的域名作为变量 [英] Domain name in URL as variable

查看:140
本文介绍了URL中的域名作为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的.htaccess文件具有以下代码:

My .htaccess file has the following code:

RewriteEngine on
RewriteRule ^/?(.*)$ index.php?domain=$1 [L]

我正在尝试从以下网址获取域名作为变量:

I'm trying to get domain names as variables from URLs like:

hxxp://www.example.com/www.domain.name或

hxxp://www.example.com/www.domain.name or

hxxp://www.example.com/subdomain.domain.name或

hxxp://www.example.com/subdomain.domain.name or

hxxp://www.example.com/domain.name

hxxp://www.example.com/domain.name

但是使用$ _GET ['domain']时,我的变量始终是'index.php',而不是域名.

but with $_GET['domain'] my variable is always 'index.php' and not the domain names.

使用hxxp://www.example.com/domain/www.domain.name和.htaccess代码

With hxxp://www.example.com/domain/www.domain.name and .htaccess code

RewriteEngine on
RewriteRule ^domain/?(.*)$ index.php?url=$1 [L]

一切正常,但我想从网址中删除域/"部分.

everything is OK, but I would like to remove the 'domain/' part from the URLs.

我已经搜索了此内容,但找不到任何内容.有人可以帮我吗?

I've searched for this, but couldn't find anything. Could someone please help me with this?

推荐答案

类似

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?domain=$1 [L]

在这种情况下,$ 1将是:

in this case $1 will be:

http://site/www.example.com        $1 = www.example.com
http://site/www.example.com/xyz    $1 = www.example.com/xyz

这篇关于URL中的域名作为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆