Jump to content

subdomain mod_rewrite


vaskovasilev

Recommended Posts

Hello to all ,

i have some problems with mod_rewrite rules and i aks for help .

 

i have working code that redirects domain.com/username/servicesid to domain.com/index.php?page=Profile&user=username&services_id=servicesid

i want to make subdomain rewrite ..

 

username.domain.com/servicesid to the same url domain.com/index.php?page=Profile&user=username&services_id=servicesid

 

here is my code :

RewriteRule ^([^/]+)/([a-z\d]{32})/(\d{4}-\d{2}-\d{2})$ index.php?page=Profile&user=$1&services_id=$2&date=$3 [L]
RewriteRule ^([^/]+)/([a-z\d]{32})$ index.php?page=Profile&user=$1&services_id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f

 

this is for rewriting only the subdomain :

 

RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([^/]+).domain.com [NC]
RewriteRule (.*) index.php?page=Profile&user=%2 [NC,QSA] 

 

can you please help me to make the code working .

also when i open username.domain.com , i cannot open the css , js .. images files .

 

Link to comment
https://forums.phpfreaks.com/topic/264928-subdomain-mod_rewrite/
Share on other sites

  • 2 months later...

Try to have a URL pattern like /service to be more specific and not apply to images/static files.

 

For example

http://123.domain.com/service/456 -> http://www.domain.com/index.php?page=Profile&user=123&services_id=456

 

Following rule will work:

 

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.domain\.com$ [NC]

RewriteCond %{HTTP_HOST} ^(.+)\.domain.com$ [NC]

RewriteRule ^service/(.*)[$ index.php?page=Profile&user=%1&services_id=$1 [L]

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.