【问题标题】:.htaccess, mod_rewrite to domain, subdomain and queries.htaccess、mod_rewrite 到域、子域和查询
【发布时间】:2017-04-19 17:19:08
【问题描述】:

我有这个链接:

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

我需要这样:

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

事实上,“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]

有人知道我该如何实现这一目标吗?谢了!

【问题讨论】:

    标签: php apache .htaccess mod-rewrite redirect


    【解决方案1】:

    几个小时后,我明白了:

    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]
    

    如果将来有人需要,\w+ 允许我使用与生成 URL 的查询相同的名称。感谢您的帮助 Giovanni,一遍又一遍地模拟它并采用您的重写规则,引导我找到答案!

    【讨论】:

      【解决方案2】:

      我相信这个特定代码的答案应该是这样的:

      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]
      

      简单解释一下我在这里做了什么:

      1. 我设置了重写的基数(将结果放在基数之后)
      2. 检查请求的查询是否不是目录
      3. 检查请求的查询是否不是文件
      4. 检查请求的查询是否包含pwreset.php?key=something 并将其重写为base/suporte/?ccce=pwreset&key=something
      5. 重定向到实际重写的url

      我希望这会有所帮助,否则我可能需要在代码中进行一些调整

      【讨论】:

      • RewriteBase 返回错误 500 页面... :( 我非常有信心这将是解决方案...但仍在尝试...任何想法?Tks!!
      猜你喜欢
      • 2016-07-06
      • 2013-08-04
      • 1970-01-01
      • 2012-03-25
      • 2013-07-14
      • 2013-01-26
      • 1970-01-01
      • 1970-01-01
      • 2011-04-23
      相关资源
      最近更新 更多