So I have 2 domain names on one server 2 different sites I have mod-rewrite on the one domain name which I would like to work for the one domain name only but when I upload the .htaccess file the 1 domain name works great but the other site / domain name shows
Not Found
The requested URL was not found on this server.
Additionally, a 404 Not Found _error_ was encountered while trying to use an ErrorDocument to handle the request.
If I remove the mod rewrite file the second site works and shows but the first site needs the mod rewrite to work is there any way to set the mod rewrite to only run for the one domain name?
Just wanted to add the main domain name is in the root and the second domain name is in a file in the root so I want all the conditions to work for domain name 1 which is in the root but not domain name 2 which is in a folder in the root. When I visit domain name 2 I get a 404 error.
options -multiviews options All -Indexes <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} mydomainname.com$ [NC] RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^home$ index.php RewriteRule ^dashboard$ dashboard.php RewriteRule ^advertiser$ advertiser.php RewriteRule ^add_campaign$ add_campaign.php RewriteRule ^edit_campaign$ edit_campaign.php RewriteRule ^stats$ view_statistics.php RewriteRule ^login$ login.php RewriteRule ^logout$ logout.php RewriteRule ^withdrawals$ withdrawals.php RewriteRule ^register$ register.php RewriteRule ^report$ report.php RewriteRule ^referrals$ referrals.php RewriteRule ^contact$ contact.php RewriteRule ^add_wallet$ add_wallet.php RewriteRule ^payment_page$ payment_page.php RewriteRule ^forgot_password$ forgot_password.php RewriteRule ^my_account$ my_account.php RewriteRule ^(admin)($|/) - [L] RewriteRule ^([A-Za-z0-9-]+)/?$ view_link.php?s=$1 [L] RewriteRule ^page_([^/]+)/?$ pages.php?slug=$1 [L] </IfModule>
Advertisement
Answer
RewriteConds work only on the one RewriteRule immediately following them, so you would have to repeat them before every single one.
It might make more sense to work with a negated pattern here – check if the host name was not mydomainname.com
, and follow that by a rule that simply says, “okay we done here”, by using the [L] flag.
RewriteEngine On RewriteBase / # check if the host name was not mydomainname.com # pattern anchored at the start using ^ as well here, so that notmydomainname.com # would not be matched as well, and the . escaped # whole thing negated, by putting ! in front of it RewriteCond %{HTTP_HOST} !^mydomainname.com$ [NC] # match absolutely anything with the . # don’t do any actual rewriting, by using - as the substitution # [L] flag to say, that’s it, we are done with the rewriting here RewriteRule . - [L] # … rest of your rules follow here RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f # …