我在localhost:8080
上有一台服务器,我通过一个名为ngrok
的隧道软件向它发送了管道请求,所以现在 我想设置我的mod_rewrite策略来映射并提供mysubdomain.ngrok.com
至localhost:8080
的任何请求,而无需重定向浏览器 。
# Turn on rewrites
RewriteEngine on
###
## Rules for "mysubdomain.ngrok.com"
###
RewriteCond %{HTTP_HOST} ^mysubdomain.ngrok.com$
RewriteRule .? %{REQUEST_URI} [L]
###
## Rules for "localhost:8080"
###
RewriteCond %{HTTP_HOST} ^localhost:8080$
RewriteRule . - [E=REWRITEBASE:/prestashop/]
RewriteRule ^api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
但我最终进入无限重定向循环! 避免这种情况和实现目标的最佳方法是什么?
[/initial] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] add path info postfix: /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api -> /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api/products
[/initial] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] strip per-dir prefix: /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api/products -> api/products
[/initial] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] applying pattern '.?' to uri 'api/products'
[/initial] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] RewriteCond: input='mysubdomain.ngrok.com' pattern='^mysubdomain.ngrok.com$' => matched
[/initial] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] rewrite 'api/products' -> '/prestashop/api/products'
[/initial] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] internal redirect with /prestashop/api/products [INTERNAL REDIRECT]
[/initial/redir#1] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] add path info postfix: /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api -> /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api/products
[/initial/redir#1] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] strip per-dir prefix: /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api/products -> api/products
[/initial/redir#1] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] applying pattern '.?' to uri 'api/products'
[/initial/redir#1] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] RewriteCond: input='mysubdomain.ngrok.com' pattern='^mysubdomain.ngrok.com$' => matched
[/initial/redir#1] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] rewrite 'api/products' -> '/prestashop/api/products'
[/initial/redir#1] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] internal redirect with /prestashop/api/products [INTERNAL REDIRECT]
...
[/initial/redir#10] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] add path info postfix: /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api -> /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api/products
[/initial/redir#10] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] strip per-dir prefix: /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/api/products -> api/products
[/initial/redir#10] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] applying pattern '.?' to uri 'api/products'
[/initial/redir#10] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] RewriteCond: input='mysubdomain.ngrok.com' pattern='^mysubdomain.ngrok.com$' => matched
[/initial/redir#10] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] rewrite 'api/products' -> '/prestashop/api/products'
[/initial/redir#10] [perdir /Users/root/dev/bitnami-ps1/apps/prestashop/htdocs/] internal redirect with /prestashop/api/products [INTERNAL REDIRECT]
答案 0 :(得分:0)
查看日志和规则我可以看到此规则导致无限循环:
RewriteCond %{HTTP_HOST} ^mysubdomain.ngrok.com$
RewriteRule .? %{REQUEST_URI} [L]
因为它无条件地为domain = mysubdomain.ngrok.com
只需将其注释掉,循环就会修复。