【问题标题】:Rewrite rules with query strings for subdomains with rootdomain使用根域的子域的查询字符串重写规则
【发布时间】:2013-01-19 14:30:20
【问题描述】:

我不是 .htaccess 方面的专家。我想将我的新闻和博客网址(带或不带 www)重写为:

bdnews24.com/reporter.php?u=姓名 to-> bdnews24.com/Name

m.bdnews24.com/reporter.php?u=名称 to-> m.bdnews24.com/Name

img.bdnews24.com/image.php?id=791011.jpg to-> img.bdnews24.com/791011.jpg

bdnews24.com/details.php?id=100200300 to-> bdnews24.com/100200300

我当前的 .htaccess 文件在下面,它没有按我的意愿工作。 这会捕获所有请求 URI,如果不存在,它将转到 index.php?u=ANYTHING

Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# AlegroCart REWRITES START
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php/$1 [L,QSA]

【问题讨论】:

  • 添加 .htaccess 文件的详细信息后,您应该通过给出一个不起作用的示例 URL、您希望它重写的 URL 以及它错误地重写的 URL 来澄清问题到(或未能重写)。以下是相关帖子的链接和查询字符串重写指南:stackoverflow.com/questions/14363132/…statichtml.com/2010/mod-rewrite-baseon-on-query-string.html
  • Options +FollowSymlinks RewriteEngine On RewriteBase / # AlegroCart REWRITES START RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) index.php /$1 [L,QSA]

标签: apache .htaccess


【解决方案1】:

根据您提供的信息,这组规则应该可以满足您的需求:

RewriteCond {%QUERY_STRING} ^u=(.*)
RewriteCond %{HTTP_HOST} ^(m.|www.)?bdnews.com$
RewriteRule ^reporter.php /%1?

RewriteCond {%QUERY_STRING} ^id=(.*)
RewriteCond %{HTTP_HOST} ^img.bdnews.com$
RewriteRule ^image.php /%1?

RewriteCond {%QUERY_STRING} ^id=(.*)
RewriteCond %{HTTP_HOST} ^(m.|www.)?bdnews.com$
RewriteRule ^details.php /%1?

首先匹配查询字符串,然后匹配主机名,然后将原始查询字符串 (%1) 重写为新 URL。

【讨论】:

  • 感谢大卫的回复。继续。
猜你喜欢
  • 1970-01-01
  • 2011-10-20
  • 1970-01-01
  • 1970-01-01
  • 2014-07-15
  • 2015-09-10
  • 2014-06-09
相关资源
最近更新 更多