Page 1 of 2

Help with mod-rewrite / apache errorhandling

Posted: Sun Aug 06, 2006 12:26 pm
by hgoor
Hi,

I am very close to being able to migrate to Linux for my blog, but I have run into the following: on my Ubuntu machine I would like to have nice url's for search engine friendly urls as I now have on my Windows install.

However it seems that neither apache errorhandling or mod-rewrite work.

How do I install mod_rewrite and make it work for my blog?

my blog is in /var/www (root not /serendipity)

Apache /etc/apache2

Right now I get url's like

http://192.168.1.103/index.php?/archive ... _here.html

Now, I know that the index.php? part is a problem with search engines...

Help anyone? :shock:

Re: Help with mod-rewrite / apache errorhandling

Posted: Sun Aug 06, 2006 12:28 pm
by garvinhicking
Hi!

You must configure s9y to use URL Rewriting in the configuration!

If you get those index.php? urls it only means that s9y is not set to use URL Rewriting. :)

Best regards,
Garvin

Re: Help with mod-rewrite / apache errorhandling

Posted: Sun Aug 06, 2006 12:35 pm
by hgoor
garvinhicking wrote:Hi!

You must configure s9y to use URL Rewriting in the configuration!

If you get those index.php? urls it only means that s9y is not set to use URL Rewriting. :)

Best regards,
Garvin
Yeah I understand that: but when I set it to that it doesn't work and I get 404 errors..

Apache mod-rewrite seems to NOT be be installed with apache...

Hence my question: how do I install mod-rewrite!

Re: Help with mod-rewrite / apache errorhandling

Posted: Sun Aug 06, 2006 12:38 pm
by garvinhicking
Hi!

If you get 404 errors in that case, your Apache is not accepting s9y's .htaccess. You must make sure your apache virtualhost has "AllowOverride All" set.

For instaling mod_rewrite, please consult the Apache documentation :)

Best regards,
Garvin

Posted: Sun Aug 06, 2006 12:46 pm
by hgoor
Ok, this is very complicated for me: where and how do I set that "AllowOverride All" ?? :shock:

Does this use mod_rewrite?

I wish I could give a thrustworty person access to my server to just set all this damn shit for me... :evil:

(ps: I have webmin etc.. installed)

Posted: Sun Aug 06, 2006 12:50 pm
by garvinhicking
Hi!

You must set allowOverride All in your apache's httpd.conf inside the <VirtualHost> container that is used for your webroot. :)

If you use webmin to maintain this, you might need to check the webmin documentation on how to enabled AllowOverride for specific hosts...

Best regards,
Garvin

Posted: Sun Aug 06, 2006 12:59 pm
by hgoor
Man, why it all this *** so complicated? On XP you just friggin install XAMPP and it goes...

Ok: I have located that apache.conf but it has MANY lines where it gives the option Allowoverride...

Which one do I need??????

Posted: Sun Aug 06, 2006 1:24 pm
by hgoor
Ah! Thanks to google, here is what I needed to do:
Edit the apache configuration for my virtualhosting. I only have one virtual hosting (/var/www) that is default from installation, so I make some adjustment for that (In my case I have to edit this file /etc/apache2/sites-enabled/000-default)
sudo nano /etc/apache2/sites-enabled/000-default

Change the Allowoverride value to all for the document root directory
For example, I made change to this part of the configuration:

<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
# This directive allows us to have apache2's default start page
# in /apache2-default/, but still have / go to the right place
# Commented out for Ubuntu
#RedirectMatch ^/$ /apache2-default/
</Directory>


Finnaly, just restart the apache
sudo /etc/init.d/apache2 restart
I might add mod-rewrite later (using the above and "use apache errorhandling" have the same effect):
sudo a2enmod rewrite
PS: it turned out that mod_rewrite WAS installed but it I guess it only works in conjunction with that AllowOverride ALL :?

Posted: Mon Aug 07, 2006 11:42 pm
by hgoor
Hi,

Sadly to report that the modifications above had some adverse effect, mainly that now EVERY url is opened in the root and other urls do not work...

Back to the drawing board.. It's just that I need to RTFM on mod_rewrite

Any tips from Linux guru's are welcome!

Posted: Tue Aug 08, 2006 11:39 am
by garvinhicking
Hi!

What do you mean with "EVERY url is opened in the root"? It sounds like the FAQ on http://www.s9y.org/11.html#A13 ?

Best regards,
Garvin

Posted: Thu Aug 10, 2006 9:35 pm
by hgoor
garvinhicking wrote:Hi!

What do you mean with "EVERY url is opened in the root"? It sounds like the FAQ on http://www.s9y.org/11.html#A13 ?

Best regards,
Garvin
OMG! You're so right! I am very very sorry that I was dumb enough not to look this up! :oops:

Posted: Thu Aug 10, 2006 9:47 pm
by hgoor
Ok, I must still be doing something wrong.

I put a .htaccess in another dir and put this in it:

rewriteengine Off

Then I restarted my Apache and tried to access the dir...

Once again I got redirected to / where Serendipity resides?

Posted: Fri Aug 11, 2006 9:54 am
by garvinhicking
Hi!

Maybe you are only calling an url like http://yourblog/s9y/yourdir/ and NOT giving a filename?

In this case you also need to put a "DirectoryIndex index.php index.html index.whateverelseyouneed" into your .htaccess of that directory.

Always when you don'T specifiy a filename to a directory, Apache needs to lookup which file it should serve. By default you configure a list of Index Files in the "DirectoryIndex" option, this is usually "index.htm index.html index.php". In this order, Apache looks for an existing file.

When serendipity puts its .htaccess in place, it routes all accesses to its index.php. So for every subdirectory you will need to "restore" the proper DirectoryIndex to use.

Regards,
Garvin

Posted: Fri Aug 11, 2006 6:14 pm
by hgoor
Ok, I am trying to get the mod_rewrite to work for me on my Ubuntu server to give me nice SEF (search engine friendly) url's.

However: as it seems (see above) I need to put a htaccess in every other directory that I want to use (See the S9y FAQ)

http://www.s9y.org/11.html#A13.

The solution stated in the FAQ is:
You need to put a .htaccess file into each subdirectory which is not related to Serendipty. The only contents of this file needs to be "rewriteengine Off". With this you tell the Webserver that the directory is independent from Serendipity and thus no Serendipity Rewrite-Rules shall be applied
However when you check the official Apache .htaccess guide they actually tell you that this is not so good (apart from the fact it doesn't seem to work for me anyway), and I quote:
In general, you should never use .htaccess files unless you don't have access to the main server configuration file. There is, for example, a prevailing misconception that user authentication should always be done in .htaccess files. This is simply not the case. You can put user authentication configurations in the main server configuration, and this is, in fact, the preferred way to do things.

(...) in general, use of .htaccess files should be avoided when possible. Any configuration that you would consider putting in a .htaccess file, can just as effectively be made in a <Directory> section in your main server configuration file.

There are two main reasons to avoid the use of .htaccess files.

The first of these is performance. When AllowOverride is set to allow the use of .htaccess files, Apache will look in every directory for .htaccess files. Thus, permitting .htaccess files causes a performance hit, whether or not you actually even use them! Also, the .htaccess file is loaded every time a document is requested. (...)

The second consideration is one of security. You are permitting users to modify server configuration, which may result in changes over which you have no control. Carefully consider whether you want to give your users this privilege. Note also that giving users less privileges than they need will lead to additional technical support requests.(...)
See: http://httpd.apache.org/docs/2.0/howto/htaccess.html

Now, this is pretty all confusing for me.... :shock:

And I do care about performance as well....

So bottomline: is there another way to use mod_rewrite - or any other solution to get SEF url's for that matter - without having to use .htaccess files that pulls your performance down?

Also: it seems that S9y is using .htaccess to enable it to use mod_rewrite in a way to create SEF url's, however when I look at other systems (like Wordpress) they do not seem to need this? So what about a less cumbersome alternative that does not force me to put a .htaccess in every directory I would like to add to my server??

Posted: Fri Aug 11, 2006 8:05 pm
by judebert
Sure, you could set it up in the <Directory> section, if you felt like it. It would improve performance, but you might not notice it unless your webserver came under heavy load.

Of course, Serendipity doesn't usually have access to the main server configuration file, and therefore it's written to modify the .htaccess when mod_rewrite is enabled. To get the performance increase, you'd have to disable (I believe) AllowOptions, then duplicate all the Serendipity .htaccess functionality in your main server config file.

As the sysop of a server where multiple users all want to write their own redirection rules and options, that could get pretty tedious. So most providers allow the users to acess the .htaccess.

This *is* a security risk, as mentioned in the document you referenced. Stupid users might forget to forbid outside access to their .htaccess, allowing a hacker to completely hijack their site simply by uploading a new .htaccess. Even if the hacker can only read the file, he gets valuable information that could help him plan a second attack.

WordPress does require .htaccess files, just like Serendipity. You could do the configuration in the main server config, but an Apache forum might be more helpful than the Serendipity-specific info you'd get here.

You also don't need an .htaccess in every directory. There should be one .htaccess in the Serendipity directory, which Serendipity will maintain on its own. Then you only need additional .htaccess files in the subdirectories of the Serendipity directory that you wish to be directly accessible to the outside world. For instance, if your website file system looks like this:

Code: Select all

/
/business
/gallery
/serendipity
/serendipity/custom_static
/the_old_site
In this case, Serendipity will only create an .htaccess in the /serendipity directory, and it will not affect access to the /business, /gallery, or /the_old_site directories. If you want someone to be able to reach a URL like http://serendipity/custom_static/index.html, you will need to add an .htacess to it. But you won't have to add .htaccess file to the other directories.

Finally, the performance hit isn't great enough to prevent major providers from using .htacess files, so unless you're planning on getting hit like Google, you probably don't need to worry about it. (Of course, this is advice from a Serendipity tech; you might want to verify on an Apache forum.)