Mod Rewrite expert, I need help

sodapopinski

Well-Known Member
Aug 13, 2001
90
2
308
I want to set a website where user can get theirname.mydomain.com.

Lets say my domain is domain.com and I already activated wild card setting into the httpd.conf config.

What I want:

1. When abc.domain.com accessed, the server will process domain.com/index.php?user=abc

2. When abc.domain.com/product_1_rose.html accessed, the server will process domain.com/index.php?user=abc&prodid=1&prodname=rose

(note abc, 1 and rose are the any number and words depending on user type in browser)

I tried the following config:
------------------------------------------------------------------------------------------
RewriteCond %{HTTP_HOST} ^((?!www\.)[^.]+)\.domain\.com$
RewriteCond %{REQUEST_URI} !^/index\.php$ [NC]
RewriteRule ^(.*)$ /index.php?user=%1
RewriteRule ^productid_([0-9]+)_([0-9a-z-]).html$ /index.php?prodid=$1&prodname=$2&user=%1
------------------------------------------------------------------------------------------

But, it doesnt work. When opening abc.domain.com/product_1_rose.html, it will open the abc.domain.com default page.
If I removed rule: RewriteRule ^(.*)$ /index.php?user=%1, the rule for abc.domain.com/product_1_rose.html works well, BUT abc.domain.com failed to load into the browser.
So, How can make both of these rule work?

Anybody have the idea? I'm willing to send some $ by paypal if the code works ;p

Thank you very much.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,258
463
Hello :)

You will likely receive more user-feedback on custom Mod_Rewrite rules on a website where more discussions of Mod_Rewrite occur, such as StackOverflow.

Thank you.