0

Recently I solved my issue with mod_rewrite to redirect a domain to a subfolder. Now that I've fixed my original issue, I've hit a another wall.

Here is an example structure:

/
/index.php
/content/
/content/styles.css
/domain/
/domain/index.php

For simplicity, /domain/ is the current and top-most folder. In /domain/index.php I am trying to access /content/styles.css. How can I accomplish this? Assume there is no web link to the previous directories. Also ../ does not work as ../ returns the same directory as ./.

I thought of a way, but my .htaccess skills aren't very strong and I don't want to spend hours or days piecing together an answer. Let's say I have:

<link rel="stylesheet" type="text/css" href="content/styles.css" />

If I am right, href performs a request for the file. How can I use .htaccess to capture the request and point it to the correct folder? Like if the query string looks like ^/content/(.*)$, and rewrite it back one directory to access ../content instead.

Hopefully this made some type of sense.

2
  • just to clarify, is /content/ inside /domain/. eg /domain/content/ ? Commented May 16, 2011 at 9:05
  • @Ben, no. Assume / is root. Both domain/ and content/ are subdirectories of /. Commented May 18, 2011 at 1:42

4 Answers 4

3

You could use an Alias:

<VirtualHost *:80>
    DocumentRoot "/domain"
    Alias /content "/content"
</VirtualHost>
Sign up to request clarification or add additional context in comments.

2 Comments

Where would this go? If it's for .htaccess, does it go into the (root) / or the /domain/ .htaccess?
You have to put it in your httpd.conf (or in an include file); check this: httpd.apache.org/docs/2.0/mod/mod_alias.html#alias
2

You could create a dummy /domain/content directory with another .htaccess file which has something like

RewriteRule ^([^/]+)$ /content/$1 [NC,L]

Comments

1

if /content/ is NOT inside /domain/ and /domain/ is your DOCUMENT_ROOT on your webserver, then you can't access the /content/ folder at all using a <link> tag & mod_rewrite.

You could access it via PHP and include it's contents, but that's a different story.

Comments

0

I considered that;

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

exist in your .htaccess file. Why aren't you trying like that?

$dir = dirname(__FILE__);
$link = $_SERVER['HTTP_HOST'];
// $link = preg_replace('/^www\./i', '', $link);

for hrefs;

href="<?php echo $link . '/content/content.css'; ?>"

for imports;

include($dir . '/example.php');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.