admin管理员组文章数量:1393060
On our server we have the domain, feedback.meridian.co.nz
.
The domain, surveys.consumerlink.co.nz
, is hosted on another server.
We're trying to create an .htaccess
file with rules which will redirect:
.dll/Frames?quest=1
to:
.dll/Frames?quest=1
but still display .dll/Frames?quest=1
in the address bar (i.e., URL masking).
From time to time the quest
number may change, so it would be good if it could redirect
.dll/Frames?quest=
to
.dll/Frames?quest=
and preserve whatever number is included after ?quest=
.
I tried asking Gemini AI how to do this. I initially asked it just about redirecting the full URL and it suggested the following code:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^scripts/dubinterviewer\.dll/Frames\?quest=1$ .dll/Frames?quest=1 [P,L]
I have spent a great amount of time Googling how to do masked redirects and I can also see that there are similar threads to this here in StackOverflow and the answers all point to the same kind of code as above, so looking at the above code, as far as I can tell, it SHOULD work! But instead, if I try to go to .dll/Frames?quest=1
I get a "404" error.
I then asked Gemini AI about doing the redirect while preserving the whatever comes after the "?quest=" paramenter and it gave me this code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^feedback\.meridian\.co\.nz$ [NC]
RewriteRule ^scripts/dubinterviewer\.dll/Frames\?quest=(.*)$ .dll/Frames?quest=$1 [P,L]
</IfModule>
However, this still results in a "404" error.
I have also asked ChatCPG and it gave me this code:
RewriteEngine On
# Enable URL masking (proxying the request)
RewriteCond %{HTTP_HOST} ^feedback\.meridian\.co\.nz$ [NC]
RewriteCond %{REQUEST_URI} ^/scripts/dubinterviewer\.dll/Frames$ [NC]
RewriteCond %{QUERY_STRING} ^quest=(\d+)$ [NC]
RewriteRule ^scripts/dubinterviewer\.dll/Frames$ .dll/Frames?quest=%1 [P,L]
Again, it really looks like it SHOULD work, however this one results in an "Internal Server Error"!
For now, until I can get this resolved, I am using the code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) /$1 [R=301,L]
This is making the redirect work just fine, but without the masking.
Any ideas where I'm going wrong here?
On our server we have the domain, feedback.meridian.co.nz
.
The domain, surveys.consumerlink.co.nz
, is hosted on another server.
We're trying to create an .htaccess
file with rules which will redirect:
https://feedback.meridian.co.nz/scripts/dubinterviewer.dll/Frames?quest=1
to:
https://surveys.consumerlink.co.nz/scripts/dubinterviewer.dll/Frames?quest=1
but still display https://feedback.meridian.co.nz/scripts/dubinterviewer.dll/Frames?quest=1
in the address bar (i.e., URL masking).
From time to time the quest
number may change, so it would be good if it could redirect
https://feedback.meridian.co.nz/scripts/dubinterviewer.dll/Frames?quest=
to
https://surveys.consumerlink.co.nz/scripts/dubinterviewer.dll/Frames?quest=
and preserve whatever number is included after ?quest=
.
I tried asking Gemini AI how to do this. I initially asked it just about redirecting the full URL and it suggested the following code:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^scripts/dubinterviewer\.dll/Frames\?quest=1$ https://surveys.consumerlink.co.nz/scripts/dubinterviewer.dll/Frames?quest=1 [P,L]
I have spent a great amount of time Googling how to do masked redirects and I can also see that there are similar threads to this here in StackOverflow and the answers all point to the same kind of code as above, so looking at the above code, as far as I can tell, it SHOULD work! But instead, if I try to go to https://feedback.meridian.co.nz/scripts/dubinterviewer.dll/Frames?quest=1
I get a "404" error.
I then asked Gemini AI about doing the redirect while preserving the whatever comes after the "?quest=" paramenter and it gave me this code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^feedback\.meridian\.co\.nz$ [NC]
RewriteRule ^scripts/dubinterviewer\.dll/Frames\?quest=(.*)$ https://surveys.consumerlink.co.nz/scripts/dubinterviewer.dll/Frames?quest=$1 [P,L]
</IfModule>
However, this still results in a "404" error.
I have also asked ChatCPG and it gave me this code:
RewriteEngine On
# Enable URL masking (proxying the request)
RewriteCond %{HTTP_HOST} ^feedback\.meridian\.co\.nz$ [NC]
RewriteCond %{REQUEST_URI} ^/scripts/dubinterviewer\.dll/Frames$ [NC]
RewriteCond %{QUERY_STRING} ^quest=(\d+)$ [NC]
RewriteRule ^scripts/dubinterviewer\.dll/Frames$ https://surveys.consumerlink.co.nz/scripts/dubinterviewer.dll/Frames?quest=%1 [P,L]
Again, it really looks like it SHOULD work, however this one results in an "Internal Server Error"!
For now, until I can get this resolved, I am using the code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) https://surveys.consumerlink.co.nz/$1 [R=301,L]
This is making the redirect work just fine, but without the masking.
Any ideas where I'm going wrong here?
Share Improve this question edited Mar 12 at 23:16 MrWhite 46.1k8 gold badges64 silver badges88 bronze badges asked Mar 12 at 21:30 Graphic DetailGraphic Detail 1412 silver badges11 bronze badges 2 |1 Answer
Reset to default 0Apache’s RewriteRule pattern only matches the URL path and does not include the query string. In your original code, you’re trying to match the literal “?quest=1” in the pattern, but Apache strips that off before matching.
To resolve this, you need to use a RewriteCond that checks the query string. Also, to mask the URL (so the address bar doesn’t change), you need to use the proxy flag ([P]) and have mod_proxy enabled.
Try this .htaccess configuration:
RewriteEngine On
RewriteCond %{HTTPS} on
# Match the query string 'quest' parameter and capture its value
RewriteCond %{QUERY_STRING} ^quest=([0-9]+)$
# Match the URI path only (without query string)
RewriteRule ^scripts/dubinterviewer\.dll/Frames$ https://surveys.consumerlink.co.nz/scripts/dubinterviewer.dll/Frames?quest=%1 [P,L]
本文标签: Using htaccess to mask a redirect from a URL on one domain to a URL on another domainStack Overflow
版权声明:本文标题:Using .htaccess to mask a redirect from a URL on one domain to a URL on another domain - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744729761a2621977.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
ProxyPassReverse
and possibly other directives (you can only do so much with.htaccess
alone). – MrWhite Commented Mar 12 at 22:09