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
  • "Internal Server Error" - You need to check the server log for the details of this error. Gemini is clearly wrong, but ChatGPT(?) is "OK" (although unnecessarily verbose). However, you do need the necessary modules installed (mod_proxy, mod_proxy_http, etc depending on what you are doing). And, ideally, if you don't have control of the target domain, you need access to the server config to implement ProxyPassReverse and possibly other directives (you can only do so much with .htaccess alone). – MrWhite Commented Mar 12 at 22:09
  • Thanks for your response. I have been working with our server administrator on this and he assures me that the proxy module is enabled in Apache, but we suspect something else may be needed. I'll pass your response on to him to check that those other things you've mentioned are enabled. And yes, our client has access to the other domain so we'll pass this on to them as well. – Graphic Detail Commented Mar 12 at 23:22
Add a comment  | 

1 Answer 1

Reset to default 0

Apache’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