php - 使用 mod_rewrite 和 htaccess 进行 url 重定向的子域?

标签 php html .htaccess mod-rewrite

我有一个当前重定向的 mod 重写

domain.com/folder/user

domain.com/folder.php?username=user

使用:

RewriteRule ^folder/(.+)$ folder.php?username=$1 [QSA,L]

但是我需要做的是重定向 http://user.domain.com/http://www.domain.com/folder.php?username=user 。如果可能的话,我可以排除某些子域(例如 www.mail. 等)。

我该怎么做?非常感谢任何帮助:)

最佳答案

它是如何工作的:

  • http://user.domain.com/ 中提取 user 并使用 RewriteCondition 保存对其的反向引用。 .
  • 请求的主机名存储在服务器变量中。

    enter image description here Figure : The back-reference flow through a rule. In this example, a request for /test/1234 would be transformed into /admin.foo?page=test&id=1234&host=admin.example.com. Source

  • RewriteRule使用RewriteCondition的反向引用。

  • 另请参阅 RewriteRule 部分中的注释:

    If you wish to match against the hostname, port, or query string, use a RewriteCond with the %{HTTP_HOST}, %{SERVER_PORT}, or %{QUERY_STRING} variables respectively.

  • 将您的(虚拟)服务器配置为监听您想要重写的所有域,以确保所有请求都传递到您可以进行重写的服务器的同一部分/根目录。否则您需要进行内部代理。

关于php - 使用 mod_rewrite 和 htaccess 进行 url 重定向的子域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10441073/

相关文章:

java - 图片上传到服务器的php错误响应= httpclient.execute(httppost);

html - 如何在 HTML5 中使用 " "

javascript - knockout JS : adding forms in foreach bindings

.htaccess - 在AngularJS网站上获取404页面以进行刷新?

apache - 如何在 htaccess 中将除一个页面之外的所有页面定向到 HTTPS?

apache - 在我的 Laravel 应用程序上遇到 mod_rewrite 问题

php - MYSQLi 错误 : User already has more than 'max_user_connections' active connections

java - Android第三方应用服务器

如果短时间内调用两次 PHP MySQL 更新不执行

html - Canvas 对于商业应用程序来说是否过大?