Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Problem Removing a Folder from a subdomain. Simple Rewrite Condition

I have a subdomain with folders inside. We want to kill a directory.

4:47 pm on Jan 6, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Aug 25, 2008
votes: 0

We run a website and have a domain that has a subdomain. We want to kill one of the directorys and re-route all that traffic back to the root of the directory.

I tried.

RewriteCond %{HTTP_HOST} !^longisland\.domain\.com\Xbox_Services\$ [NC]
RewriteRule ^(.*)$ [longisland.domain.com...] [R=304,L]


RedirectMatch 301 [longisland.example.com...] [longisland.example.com...]


RewriteRule ^Xbox_Services/(.*) [longisland.example.com...] [R=301,L,QSA]


Redirect 301 /Xbox_Services/(.*) [longisland.example.com...]

All of the above Do not work.
I'm sure looking at it your just saying to yourself NOOB... We'll help me out.

FYI I know in previous post you say be as descriptive as possible.

Well.. Inside of longisland.example.com/Xbox_Services we have subdomains as well.


We need to just get rid of everything with the condition of Xbox Service

Ideally I want this to work because We are killing other subfolders as well:
RewriteCond %{HTTP_HOST} !^longisland\.domain\.com\Xbox_Services\$ [NC]
RewriteRule ^(.*)$ [longisland.domain.com...] [R=304,L]

7:03 pm on Jan 6, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

A review of the regular-expressions tutorial cited in our Apache Forum Charter would seem to be in order. Most of the directives posted above contain one or more 'tiny' little errors that completely stop the code from working. And *that* is the most important thing to learn about writing server configuration code: It must be perfect.

In addition to these tiny errors, there's also some misunderstanding of server variable scope in evidence: For example, HTTP_HOST contains only the requested hostname, possibly with a port number appended. It does not contain any part of the requested URL-path. Conversely, the URL-paths examined by RedirectMatch and RewriteRule contain only the URL-path, and do not contain the requested protocol or domain name.

After looking through all those attempts, the following two lines were most salvageable:

RedirectMatch 301 /Xbox_Services/ http://longisland.example.com/
RewriteRule ^Xbox_Services/ http://longisland.example.com/ [R=301,L]

Either of those two lines should work, assuming that this code goes into the /.htaccess file in a separate root directory for longisland.example.com, that you completely flush (delete) your browser cache after making any changes to your server config code, that the mod_alias and mod_rewrite modules are available, that no other modules, rules, or directives (e.g. MultiViews or AcceptPathInfo) are interfering, and that you've got the required set-up directives already in place if you're using mod_rewrite. That's a fair number of assumptions, all of which need to be confirmed.