I need to change the pattern of my url from the normal path into a subdomain. I tried write the .htaccess but it's not work.


From the url above I want to:

  1. Change the pattern to call the page so I remove sos before the domain as a subdomain. So I'd got http://sos.hello.com/
  2. I need the variable to be replaced with forward slash and suffixed with .sos. As the story is about warning : article/1/this-is-a-title.sos

I wish I could have something like this: http://sos.hello.com/article/1/this-is-a-title.sos

So I wrote :

RewriteEngine On
RewriteRule ^article/([^/]*)/([^/]*)\.sos$ /article.php?id=$1&title=$2 [L]

And guess what! It's not work. Please point me out. What I've done wrong???

1 Answer 1


In your .htaccess file:

RewriteEngine On

# Change to use subdomain
RewriteCond %{HTTP_HOST} !^sos\.hello\.com$ [NC]
RewriteRule ^(.*)$ http://sos.hello.com/article/$2 [R=301,L]

# Change to pretty URL path if no query string parameters present
RewriteCond %{QUERY_STRING} !id [OR]
RewriteCond %{QUERY_STRING} !title
RewriteRule ^(.*)$ http://sos.hello.com/article/ [R=301,L]

# Change to pretty URL path if query string parameters are present
RewriteRule ^(.*)$ /article/$1

# Change query string parameters into path
RewriteCond %{REQUEST_URI} ^(/article/article.php)
RewriteCond %{QUERY_STRING} ^id=(.*)&title=(.*)$
RewriteRule ^article/article.php(.*) http://sos.hello.com/article/%2/%3?

# Replace .php with .sos
RewriteRule ^(.*).php$ $1.sos [L]

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.