homepage Welcome to WebmasterWorld Guest from 54.237.249.10
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
404 htaccess Multi-Install
domain specific 404 for Drupal
Pass the Dutchie




msg:4242623
 9:55 am on Dec 15, 2010 (gmt 0)

Hi,

We are running a Durpal multi-site install and as such we have one .htaccess file governing all domains. As such I need to be domain specific for 404

I would like to 404 a specific URL www.example-A.com/widget/

but not

www.example-B.com/widget/

I have tried
ErrorDocument 404 www.example-A.com/widget/

But nothing happens and page loads fine which is not good as /widget/ is associated with site
www.example-B.com/widget/
leading to major duplication issues.

Thanks for any feedback,

D

 

jdMorgan




msg:4243163
 4:00 pm on Dec 16, 2010 (gmt 0)

ErrorDocument defines the handler filepath for all 404s in the URL-space that maps to the .htaccess or config file at hand. It does not 'select' the URLs to be 404'ed.

So what you need is code that forces a 404 if the URL-path is requested 'from the wrong hostname'.

Either of two methods could be used, one required by Apache 1.x but usable on all versions (and therefore more-portable across possible future hosting accounts), and the other specific to Apache 2.x:

Apache 1.x or 2.x:

# If widget/ URL-path requested from non-example-B.com host, rewrite to non-existent filepath to force 404 response
RewriteCond %{HTTP_HOST} !^example-B\.com
RewriteRule ^widget/ /filepath-which-is-known-not-to-exist.lmth [L]

Apache 2.x:

# If widget/ URL-path requested from non-example-B.com host, force 404 response
RewriteCond %{HTTP_HOST} !^example-B\.com
RewriteRule ^widget/ - [R=404,L]

Jim

Pass the Dutchie




msg:4244604
 9:09 pm on Dec 20, 2010 (gmt 0)

Hi Jim,

Thanks but server is not reacting to neither method.

Basically my wordpress blog (installed in root) is mirrored on all domains and I need to restrict it from being duplicated across all domains.

Cheers,

D

g1smd




msg:4244656
 11:30 pm on Dec 20, 2010 (gmt 0)

RewriteCond %{HTTP_HOST} !^example-B\.com
RewriteRule ^widget/ /filepath-which-is-known-not-to-exist.lmth [L]


If the above code is located at example-B.com/.htaccess and you request example-B.com/widget/ the server should return a 404 header and the 404 error page.

Clear browser cache before retesting.

Do not edit the "
/filepath-which-is-known-not-to-exist.lmth" bit. Leave it EXACTLY as it is.
jdMorgan




msg:4244679
 12:48 am on Dec 21, 2010 (gmt 0)

... Or make it something equally-unlikely to match any existing file.

This new '404 forcer' rule must precede any of WP's internal rewrite rules.

Jim

Pass the Dutchie




msg:4245150
 11:58 am on Dec 22, 2010 (gmt 0)

Thanks but nothing doing. I think the issue is due to having two htaccess files, a Drupal root .htaccess and a Wordpress .htaccess file in the root of /blog/

which is simply:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress


I have tried adding both of your suggestions to either/both files but I am not getting a 404.

Which files should I add the RewriteRule and if it is the Wordpress .htaccess then perhaps we could exempt www.othersite.com/blog/ from the rule.

Cheers,
D

jdMorgan




msg:4245446
 1:54 am on Dec 23, 2010 (gmt 0)

Adding
RewriteCond %{HTTP_HOST} ^example-B\.com
as the first RewriteCond in the WP code would prevent any but example-B requests from invoking WP.

Jim

Pass the Dutchie




msg:4246188
 11:37 am on Dec 26, 2010 (gmt 0)

season greetings!

There must be something withing Drupal that is overriding the effect that htaccess has on /blog/ as neither of these suggestions are having the desired effect.

Any idea where I should be looking? The Drupal forums are also stumped.

jdMorgan




msg:4249405
 4:29 pm on Jan 5, 2011 (gmt 0)

I'd suggest:

RewriteEngine on
#
# Force 404 on all blog requests, except for example-B/blog/
RewriteCond %{HTTP_HOST} !^example-B\.com
RewriteRule ^blog/ /filepath-which-is-known-not-to-exist.lmth [L]
#
# Begin WordPress rewrite (modified)
# Rewrite all non-blank requested URL-paths which do not resolve to physically-existing files to the WP
# script, except for image, css, and js files not generated by WP, and requests for the WP script itself.
# These exclusions greatly improve efficiency, and can often forestall a required server upgrade.
RewriteCond %{HTTP_HOST} ^example-B\.com
RewriteCond $1 !^blog/index\.php$
RewriteCond $1 !\.(gif|jpe?g|png|ico|css|js)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.+)$ /blog/index.php [L]
# END WordPress

As noted above, delete your browser cache before testing any new server-side code.

Jim

Pass the Dutchie




msg:4251269
 12:36 pm on Jan 10, 2011 (gmt 0)

Thanks Guys but something in Drupal is not permitting this to work.

I have had to use another solution which solves my problem.

Move the Wordpress blog from inside the Drupal installation to the server html root and create a virtual directory in httpd.conf file so that our blog only shows up on the specific domain.

Alias /blog/ "/var/www/web0/html/my-blog/"
<Directory "/var/www/web0/html/my-blog/">
Options Indexes MultiViews FollowSymLinks
AllowOverride ALL
Order deny,allow
Allow from all
</Directory>

Thanks again,

D

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved