3

I would like to redirect all the traffic from subdomain.domain.com to subdomain.domain.com/?appselect=app1.

I followed some of the examples here: Rewrite query string in .htaccess But they are not working for me for some reason. This is what I have so far:

RewriteEngine On
RewriteRule ^/$ /?appselect=app1 [PT,L]

But it just goes to the same page: subdomain.domain.com

Any help on this would be appreciated, thanks.

3 Answers 3

1

If you want redirect then add R flag:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^subdomain\. [NC]
RewriteCond %{QUERY_STRING} !(^|&)appselect=app1 [NC]
RewriteRule ^/?$ /?appselect=app1 [QSA,L,R=302]
Sign up to request clarification or add additional context in comments.

11 Comments

Thank you @anubhava but I got this error: This webpage has a redirect loop
Just one more question, I'm planning to force to SSL in the future. Do you think that this is going to make me discard this rule and create a brand new one or can I recycle this rule to make it force it to https? And, is it possible to hide the real URL from the address bar and just show subdomain.domain.com to the user so the user don't see the query string attached to the URL? I really appreciate your help!
If you want to hide the real URL then remove R=302 from above URL. And whenever you decide to use SSL then use that redirect rule before this rule.
Thanks anubhava, I removed R=302 and it is now showing apache test page, so is going somewhere else.
No issues mate. Just to let you know Julio's answer will cause a redirect loop.
|
1

Basically doing something like this would work. It worked for my server.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^subdomain\. [NC]
RewriteRule ^/?$ /?appselect=app1 [QSA,L,R=302]

Comments

0

try

RewriteRule ^$ /?appselect=app1 [PT,L]

1 Comment

Thank you for your response but it goes to the same page: subdomain.domain.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.