.htaccess Add an exception to 404 redirect to particular sub-directory -
the sub-directory /addon/ stores data sub-domains a.k.a addon domains. in sub-directory store primary domains data, primary domain website.com
rewriteengine on rewritecond %{http_host} ^(www.)?website.com$ [nc] rewritecond %{request_uri} ^/addon/(.*)$ rewriterule ^(.*)$ - [l,r=404]
okay part done, if enter website.com/addon/mysecondwebsite-com 404. if enter mysecondwebsite.com see contents of website.com/addon/mysecondwebsite-com.
this great, thats wanted.
now tricky part, set website.com use website.com/addon/website-com. no need tell me how configure /addon/website-com website.com. need disable 404 website.com configured use /addon/website-com/ need make sure if enter website.com/addon/website-com directory returned 404.*
my rewrite conditions mention if enter /addon/* on primary domain (website.com) returned 404 error. great addon domains because use /addon/ , not primary domain. how block /addon/* still use primary domain?
- website.com = 404 / bad (website.com/addon/website-com)
mysecondwebsite.com = 200 / good (website.com/addon/mysecondwebsite-com)
website.com/addon/mysecondwebsite-com = 404 / good
- website.com/addon/website-com = 404 / good
just full picture .htaccess file /public_html/
# part 1 block direct access /addon/ folder rewriteengine on rewritecond %{http_host} ^(www.)?website.com$ [nc] rewritecond %{request_uri} ^/addon/(.*)$ rewriterule ^(.*)$ - [l,r=404] # part 2 using /addon/website-com/ website.com directory rewritecond %{http_host} ^(www.)?website.com$ rewritecond %{request_uri} !^/addon/website-com/ rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.*)$ /addon/website-com/$1 rewritecond %{http_host} ^(www.)?website.com$ rewriterule ^(/)?$ addon/website-com/index.php [l]
replace 404 handler this:
errordocument 404 /404.shtml rewritecond %{http_host} ^(www\.)?website\.com$ [nc] rewritecond %{the_request} ^[a-z]{3,}\s/+addon/ [nc] rewriterule (?!^404\.shtml$)^.*$ - [l,r=404,nc]
Comments
Post a Comment