1

I've been trying to accomplish this type of redirection with .htaccess yet I cannot figure out the correct way of doing so (after searching google for a while):

test.example.com/more -> example.com/test.php?o=more

I tried to do the following:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)\.example\.com/(.*)$ $1.php?o=$2 [L,NC,QSA]

I'm not very understanding on how .htaccess fully works so any help with this would be appreciated.

1 Answer 1

2

You can use:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC]
RewriteRule ^([^/.]+)/?$ /%1.php?o=$1 [L,NC,QSA]
Sign up to request clarification or add additional context in comments.

2 Comments

The subdomain aspect of it is working but the query isn't going through (just leaving a blank o= according to php).
Ah it should have been $1, fixed it now.

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.