1

I'm really struggling to write my .htaccess file properly. I would like the following to happen:

  1. x.domain.com --> redirect to --> domain.com/index.php?id=x
  2. If there is a $_GET variable on the original URL, transfer this to the second URL: x.domain.com/?y --> redirect to --> domain.com/index.php?id=x&y

So far, I've managed to get as far as mentioned in the 1st point.

But can't work out where to go next to achieve the 2nd point.

Do I need to write new lines for a separate rule, or amend the current lines?

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{REQUEST_URI} !index\.php
RewriteCond %{HTTP_HOST} ^(.+?)\.domain\.com$
RewriteRule .* http://www.domain.com/index.php?id=%1 [L,P]

Any help appreciated.

0

1 Answer 1

2
...
RewriteRule .* http://www.domain.com/index.php?id=%1 [L,P,QSA]

You're looking for the QSA (query string append) flag, which appends the query string back to the rewritten URL.

Sign up to request clarification or add additional context in comments.

Comments

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.