将具有目录结构的动态子域重定向到单个文件
我有一个通配符 dns 处于活动状态的域名。我想在 htaccess 中写入的是,当用户输入 abc.domain.com/news/news-details.php 时,它应该使用参数 val=abc 向文件 news.php 发送请求。 我在 htaccess 中有以下代码:
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com
RewriteCond %{REQUEST_URI} ^news/news-details\.php$
#RewriteCond %{QUERY_STRING} !^id=.
RewriteRule (.*) /news.php?div=%1 [L]
但这会引发 404 错误。核心部分是以下两行,解释
对 www.domain.com/news/news-details.php
的请求转到 www.domain.com/news.php 和
abc.domain.com/news/news-details.php
就像 www.domain.com/news.php?val=abc
请注意,我没有重定向。网址将显示为动态子域。物理上不会有文件夹。所有文件都位于根目录中。
I have a domain name with wildcard dns active. what i want to write in htaccess is that when the user type abc.domain.com/news/news-details.php then it should send request to the file news.php with arguments val=abc.
I have in the htaccess the following code:
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com
RewriteCond %{REQUEST_URI} ^news/news-details\.php$
#RewriteCond %{QUERY_STRING} !^id=.
RewriteRule (.*) /news.php?div=%1 [L]
But this is throwing a 404 error. what is the core part are the following two lines to explain
request for www.domain.com/news/news-details.php
goes to www.domain.com/news.php
and abc.domain.com/news/news-details.php
goes like www.domain.com/news.php?val=abc
Please note that i am not redirecting. the urls will show as a dynamic sub domain. physically there will be no folder. all files are located in the root.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)