Welcome to WebmasterWorld Guest from 54.226.146.15

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess syntax question

equivalent of "../" in htaccess?

     

majjk

5:22 pm on Mar 11, 2010 (gmt 0)

10+ Year Member



Hi,
if I use

RewriteRule ^(.*)$ dir/file1.php [L]


in the directory for sub.domain.com, then browsing to sub.domain.com/whatever.php will deliver sub.domain.com/dir/file1.php, while the browser address field still display sub.domain.com/whatever.php
So far so good...

But if I want to deliver a file that is located in "../domain/file2.php" (i.e. go up one step in the directory hierarchy and then...), how would I specify that? What I have in mind is to do something like this:

RewriteRule ^(.*)$ ../domain/file2.php [L]


The problem is that using 2 dots does not seem to work in htaccess... what is the equivalent in htaccess?

g1smd

7:47 pm on Mar 11, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



For that to work, the .htaccess file would need to be located one folder up on the server and the rules adjusted to suit.

Additionally, rewriting all URL requests to one index.php file is a recipe for disaster, as your script will not be able to serve a request for /robots.txt, or for your CSS or JS files, or for requests for images, for example.

majjk

8:12 pm on Mar 11, 2010 (gmt 0)

10+ Year Member



well, was just intended as an imaginary example. In the real world I have domain.com and sub.domain.com. I want any file requests on the subdomain to be internally redirected to the main domain.

Example, sub.domain.com/whatever.php will deliver domain.com/whatever.php, and at the same time the browser address field will stay at sub.domain.com/whatever.php

the directory structure is such that both the subdomain directory and the main domain directory is contained in the same container directory (default by cpanel, so nothing I really do anything about)

jdMorgan

8:24 pm on Mar 14, 2010 (gmt 0)

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



For security reasons, mod_rewrite cannot do things like
RewriteRule ^(.*)$ ../domain/file2.php [L]

Also, if these sub-domains were created as "add-on domains" using cPanel, you may find that you cannot under any circumstances access example.com/<anything> filepaths from example.com/subdomain-folder/<anything> filepaths.

The alternatives in that case are to get a dedicated IP address, allowing you to define your subdomains as pointing to anywhere in the filesystem you like, or to use an external redirect, which *would* change the browser address bar.

Jim
 

Featured Threads

Hot Threads This Week

Hot Threads This Month