Mobile app version of vmapp.org
Login or Join
Shakeerah822

: How to mod_rewrite url with subdomain and change extension 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. http://hello.com/sos/article.php?id=1&

@Shakeerah822

Posted in: #DomainExtension #ModRewrite #Seo

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.
hello.com/sos/article.php?id=1&title=this-is-a-title.php
From the url above I want to:


Change the pattern to call the page so I remove sos before the domain as a subdomain. So I'd got sos.hello.com/ 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: sos.hello.com/article/1/this-is-a-title.sos
So I wrote :

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


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

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Shakeerah822

1 Comments

Sorted by latest first Latest Oldest Best

 

@Cugini213

In your .htaccess file:

RewriteEngine On

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

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

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

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme