简体   繁体   English

.htaccess用多个$ _GET变量重写

[英].htaccess rewriting with multiple $_GET variables

I'm really struggling to write my .htaccess file properly. 我真的很难正确地编写我的.htaccess文件。 I would like the following to happen: 我希望发生以下情况:

  1. x.domain.com --> redirect to --> domain.com/index.php?id=x x.domain.com- >重定向到-> domain.com/index.php?id=x
  2. If there is a $_GET variable on the original URL, transfer this to the second URL: x.domain.com/?y --> redirect to --> domain.com/index.php?id=x&y 如果原始网址上有$ _GET变量,请将其转移到第二个网址:x.domain.com/?y- >重定向到-> domain.com/index.php?id=x&y

So far, I've managed to get as far as mentioned in the 1st point . 到目前为止,我已经达到了第一点所提到的范围。

But can't work out where to go next to achieve the 2nd point . 但是不能算出去达到第二点的下一步。

Do I need to write new lines for a separate rule, or amend the current lines? 我需要为单独的规则写新行还是修改当前行?

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{REQUEST_URI} !index\.php
RewriteCond %{HTTP_HOST} ^(.+?)\.domain\.com$
RewriteRule .* http://www.domain.com/index.php?id=%1 [L,P]

Any help appreciated. 任何帮助表示赞赏。

...
RewriteRule .* http://www.domain.com/index.php?id=%1 [L,P,QSA]

You're looking for the QSA (query string append) flag, which appends the query string back to the rewritten URL. 您正在寻找QSA (查询字符串附加)标志,该​​标志会将查询字符串附加回重写的URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM