简体   繁体   English

.htaccess,mod_rewrite到域,子域和查询

[英].htaccess, mod_rewrite to domain, subdomain and queries

I have this link: 我有这个链接:

http://portal.tribee.com.br/pwreset.php?key=3ef73d15ddb6e307f5c12ffd5bed7d7f

And I need to make it like this: 我需要这样:

http://tribee.com.br/suporte/?ccce=pwreset&key=98f7459b8d46e3a54ed76965825c894a 

As a matter of fact, the "pwreset.php" is one of the pages... There's clientarea.php also and others... If I can make a generic htaccess wich allows me to keep my main domain, would be the perfect match... I've already tryied lots of combinations.. such as: 事实上,“ pwreset.php”是其中的页面之一...还有clientarea.php和其他...如果我可以使通用htaccess允许我保留我的主要域名,那将是完美的匹配...我已经尝试了很多组合..例如:

RewriteCond %{REQUEST_URI}  ^/pwreset\.php$
RewriteCond %{QUERY_STRING} ^key=(.*)$
RewriteCond %{HTTP_HOST} ^portal.tribee.com.br$
RewriteRule ^(.*)$ http://tribee.com.br/suporte/?ccce=&%1. [R=302,L]
RewriteRule ^$ http://tribee.com.br/suporte/?ccce=pwreset&key=%1 [R,L]

Does anyone has an idea how can I achieve this? 有谁知道我该如何实现? Tks! TKS!

I believe that the answer to this particular code should be something like this: 我相信这个特定代码的答案应该是这样的:

RewriteEngine On
RewriteBase http://tribee.com.br
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^pwreset.php?key=(.+)$ /suporte/?ccce=pwreset&key=$1 [R=302,L]

To simply explain what i did here: 简单地解释一下我在这里所做的事情:

  1. I set the base for rewriting (places the result AFTER the base) 我设置了重写的基础(将结果放置在基础之后)
  2. checked if the requested query is not a directory 检查请求的查询是否不是目录
  3. checked if the requested query is not a file 检查请求的查询是否不是文件
  4. check if the requested query contains pwreset.php?key=something and rewrite that to the base/suporte/?ccce=pwreset&key=something 检查请求的查询是否包含pwreset.php?key=something并将其重写为base/suporte/?ccce=pwreset&key=something
  5. redirect to the actual rewritten url 重定向到实际重写的URL

I hope this helped, else I might need to adjust something in the code 我希望这会有所帮助,否则我可能需要调整代码中的某些内容

After many hours, I got it: 几个小时后,我明白了:

RewriteCond %{HTTP_HOST} ^portal.tribee.com.br$
RewriteCond %{REQUEST_URI}  ^(.*)\.php$
RewriteCond %{QUERY_STRING} ^key=(\w+)$
RewriteRule ^(.*)\.php$ http://tribee.com.br/suporte/?ccce=$1&key=%1 [R=301,L,NC]

If anyone needs in the future, the \\w+ allowed me to use the same name used to get the query to the generated URL. 如果将来有人需要,则\\w+允许我使用用于查询生成的URL的相同名称。 Thanks for your Help Giovanni, simulating it over and over and taking your rewrite rule, leaded me to the answer! 感谢您的帮助Giovanni,一遍又一遍地模拟它,并采用了重写规则,使我找到了答案!

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

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