Forum Moderators: phranque
I just bought a domain, http://www.example.com, from Yahoo and I am using my cousin's paid hosting with it. The only problem is that my domain points to his website instead of mine. I need it to point to http://www.example.com/example/ but display http://www.example.com in the address bar. It needs to work exactly how it would with the /example/ in the address bar, just without it. Like, if you were to go to http://www.example.com/example/profile.php?id=andrew , I want it to go to the same page but with this url: http://www.example.com/profile.php?id=andrew . I don't just want a redirect.
Pretty much, I just want the /example/ to be out of the address bar even though the files are located in that folder. Sorry if this sounds confusing.
[edited by: jdMorgan at 4:27 am (utc) on Dec. 31, 2005]
[edit reason] No URLs, please. See Terms of Service. [/edit]
It's also possible you may be able to use the existing site's control panel to define the new domain and its folder.
This is sort of half an answer, I'll try to add more later if time allows.
Jim
p.s. sorry about the links :(
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.net
RewriteCond %{REQUEST_URI}!^/dir/
RewriteRule ^(.*)$ [domain.net...] [R=301,L]
When I go to www.domain.net, it displays www.domain.net/dir/. How can we get the /dir/ out?
I found this on the search...
------------
If abc.com is your original domain and xyz.com is the domain alias, and
you want people going to abc.com to see one site and people going to
xyz.com to see a different site, and you want the hostname to stay as
the user typed it, make a directory called xyz under /htdocs/www and put
the xyz.com website in it. Then use mod_rewrite in an .htaccess file in
/htdocs/www
RewriteEngine On
RewriteCond %{HTTP_HOST} xyz.com$ [NC]
RewriteCond %{REQUEST_URI}!^/xyz/.*$
RewriteRule ^(.*)$ /xyz/$1
Now when people go to abc.com they will see the site in /htdocs/www.
When people go to xyz.com, they will be served pages from
/htdocs/www/xyz and the URL in their browser will not change the
hostname or show them the /xyz/.
------------
I put this in:
RewriteEngine On
RewriteCond %{HTTP_HOST} domain.net$ [NC]
RewriteCond %{REQUEST_URI}!^/dir/.*$
RewriteRule ^(.*)$ /dir/$1
and it says it cannot find the directory, but if i put this in
RewriteEngine On
RewriteCond %{HTTP_HOST} domain.net$ [NC]
RewriteCond %{REQUEST_URI}!^/dir/.*$
RewriteRule ^(.*)$ /dir/index.php$1
it loads the index page but without any images or style sheets...I think this is because it is looking in the wrong directory. Although, the url does stay how it is supposed to and the links no longer contain the /dir/ in them, but none of the links work because it thinks the page is in www.domain.net/file.php, when it is really located in www.domain.net/dir/file.php; it is just supposed to display www.domain.net/file.php... Make any sense? :P lol...I should probably just wait for you to respond now, hehe....
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{REQUEST_URI} !^/dir
RewriteRule ^(.*)$ /dir/$1 [L]
Plug in this code, request a page from your domain as a test, and then go look at your server error log file. It will likely indicate the adjustment needed to the local URL-path to get this working. Specifically, look at *what* directory path the error log says was not found, and compare that to what you typed in, plus the added '/dir/' path-part. You will likely find that there is extra path information in the directory it's trying to fetch, and that problem can usually be handled by using RewriteBase or by modifying the RewriteRule itself.
Added: I removed unneeded ".*$" tails and left your domain unanchored so the rule won't fail if a port number is appended to the request, which is perfectly valid. For example, a request might be for "example.com:80/page.php"
Jim
The problem is probably with your server. In addition to not allowing you to view your error log --a basic requirement to debug complex stuff like mod_rewrite and server-side scripts-- it seems to be mis-configured.
The options seem to be limited to:
a) Get your host to fix this.
b) Change hosts.
Sometimes we just run into a situation where code that should work doesn't work. And it is usually because the host has misconfigured something -- either by mistake, through ignorance, or because they believe it will make a shared server 'safer'. Without an error log to examine, there's just no way to find out which of these is the problem.
Jim
Your example:
RewriteCond %{REQUEST_URI} !^/dir
My suggestion:
RewriteCond %{REQUEST_URI} !^/dir/
And this is more efficient:
(By using %{REQUEST_URI} in the substitution, we can use the Regex for loop stopper.)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule !/*dir/ /dir%{REQUEST_URI} [L]
For RewriteRule related issues, guessing with limited info is often pure waste of time for everyone, as many things can influence the outcome.
Actual URL tested, current .htaccess, and error.log output, for example, will help others to pinpoint the cause.
Also, you should be aware that some script will react badly to such setup, and you may need to modify the script or configuration.