Apache base URL for subdirectory? - apache

I've got my site in htdocs/mysite which I'll be using to test/develop my website locally. Problem is, now all my URLs in my HTML/CSS need to begin with mysite whereas they won't on the product environment. What's the best way around this? Is there something I can add to httpd.conf to tell it anything in mysite should be relative to mysite? I'm still an apache noob, so please by detailed :)

Can you not just omit the preceding slash on each file reference? i.e.,
.myClass {
background-image: url(images/stuff.png);
}
I'm guessing you want something more substantial. Use an .htaccess file in the /mysite directory. All the info you need is here: RewriteBase

Related

How do I configure apache for a custom directory?

Trying to configure apache2 to load example.com/forum/ from a different document root, relative to the site root. Forums are installed somewhere else on the server.
Is there a directory alias command? I've found the alias configuration entry for apache, but had no luck.
Basically, I want example.com to have the same directory its always had, but example.com/forum/ to be hosted somewhere else, on the same server.
I tagged this question with mod_rewrite because I thought maybe it would be the key, here.
Cheers!
Alias is the right way, unless you have some subtlety that you didn't reveal in your question.
# http.conf
Alias /forum /usr/lib/bbs/ # or whatever
The job of Alias is to take the abstract URL coming into your system and map it to a concrete filesystem path. Once it has done that, the request is no longer an URL but a path. If there is no Alias or similar directive handling that URL, then it will get mapped to a conrete path via DocumentRoot.
If this isn't working, you have to debug it further. Are you getting errors when you access /forum? Look in the error log.
It all depends of what you want. You can "hardlink" with real path and it works (so you were right to think it could work with mod_rewrite).
Quick sample (that works on my production domains) to make an internal change (I add a subdirectory):
RewriteRule (.*) %{DOCUMENT_ROOT}/mysubfolder%{REQUEST_FILENAME} [QSA,L]
So you can easily do something like:
RewriteRule ^/forum/(.*) %{DOCUMENT_ROOT}/mysubfolder%{REQUEST_FILENAME} [QSA,L]
And my suggestion would be that if you plan to have more rewrite rules, keep everything homogeneous, i.e.: keep on using only rewrite rules, so use my suggestion above. This way you'll not get a bad mix of Alias, RewriteRules and so on. For nice and clean stuff: keep everything homogeneous.

use RewriteMap in htaccess file

How can i use RewriteMap directive in htaccess file?
When i put it there i get "RewriteMap not allowed here" error.
I know this error will disappear when put it in httpd.conf or virtualhost configuration file.
But i want to know is it possible to put it in htaccess or not?
From the documentation:
Context: server config, virtual host
so the answer is "no", I'm afraid.
As far as I know it cannot be used in htaccess.
Maybe you could check this out as an alternative: http://savride.wordpress.com/2008/09/09/rewritemap-directive-in-htaccess-file-problem/

htaccess rewrite question

I want to rewrite the url http://mydomain/myapp/fakefolder to http://mydomain/myapp/index.php
I tried the following rule but thats not working
RewriteEngine On
RewriteRule ^fakefolder$ index.php
The .htaccess file is located inside myapp.
Kindly help
Thanks
vineet
To begin with, your folder is not called vineetstore: it's called fakefolder.
The corrected rule works for me so I'd dare say your Apache installation is not configured to read .htaccess files in such location. You can easily test that: make a syntax error on purpose and see whether your site crashes.
Find your virtual host or site definition and make sure you have this directive:
AllowOverride All

Apache virtual directory without redirect

What I'm trying to accomplish is pulling content from a directory that is not the same as the url path. For example:
URL: example.com/
path: /www/production/
Currently, the root url pulls content from the path above. What I want to do is something like this:
URL: example.com/
path: /www/production/root/
So the base URL "example.com" should pull data not from /www/production/ but from /www/production/root/.
I think this is called a Virtual Directory in IIS. Is there something like this in Apache?
Edit for clarification:
I have a ton of existing content that I do not want to have to restructure yet. However, the root site is being completely rebuilt and is going to be quite a bit bigger. What I want is each microsite to have it's own directory, such that requests for example.com/ should pull content from /www/production/root/ while requests for example.com/microsite/ should still pull content from /www/production/microsite/.
Hopefully that makes more sense. :)
Its not exactly clear what your problem is. If you just want all URLs to be taken relative to some location on the server, then you can use the DocumentRoot directive:
DocumentRoot /www/production/root/
If you want to only have certain urls go to the new place, then you can either use the Alias or AliasMatch directives from the mod_alias module. These can map either prefixes on a URL, or url Regexes to other server locations. If even this isn't sufficient, you can use mod_rewrite which allows for arbitrary chains of url rewriting, but can get very hairy to maintain, so you're better off avoiding that module if you can.
http://httpd.apache.org/docs/2.0/mod/mod_alias.html
If I understand your question correctly, then the following, in your VirtualHost config, does what you're asking for:
ServerName example.com
DocumentRoot /www/production/root/

.htaccess mod_rewrite rule not working in Ubuntu

My apologies if this is an easy one. I have Googled it up the hizzy to no avail.
I am running Ubuntu 9.04, Jaunty Jackelope and Apache2. After much trouble, I finally enabled mod_rewrite, and my .htaccess file is attempting to do it's thing, but is failing. This is my setup.
In /etc/apache2/conf.d/ I have a file called apeace-public-html.conf. It reads as follows:
# makes /home/apeace/public_html/ available through /localhost/apeace
Alias /apeace /home/apeace/public_html/
And in /home/apeace/public_html/ I have the following .htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^test\.html$ index.html
Also in /home/apeace/public_html/ I have a file named index.html, but I do NOT have a file named test.html. It seems to me that this rewrite should show index.html when I try to access http://localhost/apeace/test.html. However, this is the error I get:
Not Found
The requested URL /home/apeace/public_html/index.html was not found on this server.
So the question is, what in the world am I doing wrong?
Much thanks.
-apeace
Just a guess here, but can you try to make the RewriteRule like ^test.html$ /apeace/index.html
From the error message, it seems it is translating `http://localhost/apeace/test.html to http://localhost/home/apeace/public_html/index.html
Your rewrite rule is working correctly since it's telling you it can't find "index.html". If you went to test.html and it said it can't find "test.html" then your rewrite rule would be at fault.
So what this means is that something else is wrong in your setup, whether it's a bad file or directory name somewhere, or whatever else. Make sure there's nothing basic you're overlooking.
But in answer to your question (especially the title), your htaccess is fine.