[Pro] Need htaccess to rewrite subdirectory

Hey Everyone,

We are still having an issue with our htaccess. We’ve chosen to rewrite this post because we are clarifying the issue by representing our structure within this post. Are there any advanced users that can help us with this? If you are looking for the old post that was never resolved, you can find it here.

We are having an issue with our htaccess file. Our goal is to get the pages in a subdirectory to be viewed in the URL as if it were up a level. It is a little more complicated than it sounds. To clarify, our Hosting provider is using something called a Server Alias which points multiple domains into a single hosting account htdocs where a .htaccess file which the user into the appropriate directory for that domain’s specific website content. Any kind of help would be greatly appreciated. Here is our Root Directory structure:


/htdocs/

  • .htaccess (htaccess_01)

  • Domain1/

    • .htaccess (htaccess_02a)
    • errorpage.html
    • index.html
    • page.html
    • subfolder/
      • .htaccess (htaccess_03)
      • errorpage.php
      • index.php
      • page.php
      • webyep-system/
  • Domain2/

    • .htaccess (htaccess_02b)
    • erorpage.html
    • index.html
    • page.html
  • Domain3/

    • .htaccess (htaccess_02c)
    • erorpage.html
    • index.html
    • page.html

Below is the makeup of each htaccess.

RewriteEngine On

#Rewrite for Domain 1
RewriteCond %{HTTP_HOST} ^www.domain1.com$ [NC] #Rewrites www requests to folder
RewriteCond %{REQUEST_URI} !^Domain1/.*$
RewriteRule ^(.*)$  Domain1/$1 [L]

RewriteCond %{HTTP_HOST} ^domain1.com$ [NC] #Rewrites non-www requests to folder
RewriteCond %{REQUEST_URI} !^Domain1/.*$
RewriteRule ^(.*)$  Domain1/$1 [L]


#Rewrite for Domain 2
RewriteCond %{HTTP_HOST} ^www.domain2.com$ [NC] #Rewrites www requests to folder
RewriteCond %{REQUEST_URI} !^Domain2/.*$
RewriteRule ^(.*)$  Domain2/$1 [L]

RewriteCond %{HTTP_HOST} ^domain2.com$ [NC] #Rewrites non-www requests to folder
RewriteCond %{REQUEST_URI} !^Domain2/.*$
RewriteRule ^(.*)$  Domain2/$1 [L]]


#Rewrite for Domain 1
RewriteCond %{HTTP_HOST} ^www.domain3.com$ [NC] #Rewrites www requests to folder
RewriteCond %{REQUEST_URI} !^Domain3/.*$
RewriteRule ^(.*)$  Domain3/$1 [L]

RewriteCond %{HTTP_HOST} ^domain3.com$ [NC] #Rewrites non-www requests to folder
RewriteCond %{REQUEST_URI} !^Domain3/.*$
RewriteRule ^(.*)$  Domain3/$1 [L]

This htaccess looks at what domain the viewer is requesting and sends him to the appropriate directory.

htaccess_02a

ErrorDocument 403 /errorpage.html
ErrorDocument 404 /errorpage.html

RewriteEngine on

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /([^/]+/)*index.html(?[^ ])? HTTP/
RewriteRule ^(([^/]+/)*)index.html$ http://www.domain1.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^(www.domain1.com)?$ 
RewriteRule ^(.*)$ http://www.domain1.com/$1 [R=301,L]

AddType video/mp4 .mp4

This htaccess allows this sub-directory to be used as a root and forces index.html to the domain name. Currently passive in nature meaning:

	www.domain1.com/index.html
	could also be viewed at
	www.domain1.com/Domain1/index.html

This is currently not an issue because we are not using WebYep and Disqus on this level. But depending on if we come to a resolve with the main issue, this htaccess might mirror the solution.

htaccess_03

ErrorDocument 403 /Team-SDA/errorpage.php
ErrorDocument 404 /Team-SDA/errorpage.php

RewriteEngine on

# Rewrite subdomain up one level and remove extension.
RewriteCond %{THE_REQUEST} ^GET /([^. ]+.)+php(?[^ ]*)? HTTP
RewriteRule ^(.+).php$ http://www.domain1.com/subfolder/$1 [R=301,L]

# Should work but is saying to many redirects.
# RewriteCond %{THE_REQUEST} ^GET /([^. ]+.)+php(?[^ ]*)? HTTP
# RewriteRule ^(.+.php)$ http://www.domain1.com/subfolder/$1 [R=301,L]

This htaccess is what we are currently working on. Please see the “Example Link” at the bottom of this post. It shows the reason why we are addressing this issue. This htaccess is supposed to stop Disqus from creating two instances on the same page by forcing the subdirectory to be viewed up one level. So if a viewer goes to:

	www.domain1.com/Domain1/subfolder/index.php
	it will be forced to
	www.domain1.com/Domain1/index

This way the viewer can only view the page using one URL string which means only 1 instance of Disqus can be created. The problem with our current htaccess is that it removes the extention (.php). The amendment you recommended should’ve worked but we get an error message on Safari that says there are too many redirects. I suspect it has something to do with the redirects already happening on the previous htaccess.

  1. Is there anything we can change in our htaccess to address this issue?
  2. Is there another way we should be going about this?

Example Page:

(Live Lights | 30 Years of Creativity)

Thanks,
Bernard


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I guess you have to rewrite the post and make the required changes in programming. The sub directory can also be added in the header file. You can even contact your hosting solution provider or SP for the changes in the programming or you can check HERE.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Generally, when you want to redirect a request into a folder that isn’t apparent in the URL, you need some hook to figure out whether or not to apply the rule. Can you please, in one line, give us an example of a request from a browser that you would like to have filled by an actual URI? For example, are you trying to do something like this:

In that case, you have the following things to go by – the folder /products is in the request path, and the actual file doesn’t exist there. So you can use a RewriteCond for each of those conditions to trigger the following rule, which would capture the requested filename and fulfill it from the acme/ folder.

RewriteRule products/(.*) products/acme/$1

The hosting provider’s setup doesn’t seem very standard – generally, when you want to put different domains or subdomains in a server, you set up what’s called Name-based Virtual Hosts, not hostname-based rewriting. This sounds, frankly, broken.

Name-based virtual hosting is a time-honored method of defining multiple virtual servers in a single Apache installation. The folders used in this scheme for each server’s root do not need to be peers with one another – it is possible to define a server within a server, like this:

/your_account_root
	/htdocs
		/site_1
			index.html
			/site_2
				index.html

A request for site_2.com/ would give you /your_account_root/htdocs/site_1/site_2/index.html, but if you knew it was there, so would a request for site_1.com/site_2/index.html. There are htaccess rules that could either forbid the latter request, or redirect it to the appropriate top-level domain or subdomain as necessary.

Walter

On Jan 22, 2014, at 2:09 AM, Eric Wendell wrote:

I guess you have to rewrite the post and make the required changes in programming. The sub directory can also be added in the header file. You can even contact your hosting solution provider or SP for the changes in the programming or you can check HERE.


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Forgot one detail, which would make the URL appear to be the same as the original request:

RewriteRule products/(.*) products/acme/$1 [NC,L]

Those flags at the end mean “No Change” and “Last”, and that means “don’t change the visitor’s idea of the URL, and stop executing any more rules”.

Walter

On Jan 22, 2014, at 9:25 AM, Walter Lee Davis wrote:

which would capture the requested filename and fulfill it from the acme/ folder.

RewriteRule products/(.*) products/acme/$1


freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options