...

View Full Version : Getting started with .htaccess on Debian Etch



XmisterIS
07-13-2011, 03:08 PM
I am using Apache 2.2 on Debian Etch and I'd like to get started with .htaccess

So far, I've got as far as loading the mod_rewrite module into the server, which I achieved by:

a2enmod rewrite
/etc/init.d/apache2 restart

Simple.

Now, I have a test page called "new.html" which is in the directory /var/www/public_html and in order to get things started, I want to rewrite "old.html" as "new.html".

Simple enough, but I can't seem to do it! (old.html just gives me a file-not-found error, which means the rewrite isn't working).

I've looked at three different online tutorials and each one says something different, and none of the methods described work!! (I've tried all three).

Now I am super-confused ... :confused:

Please can someone tell me how to do it, and in order to avoid the complete confusion that I have experienced so far please could you tell me:

a) Where to put the .htaccess file.

b) What needs to go in the file.

Thanks :)

Inigoesdr
07-13-2011, 03:43 PM
The .htaccess file goes in the document root(public_html in this case). Post what you are trying so we can go based on that. It should be as simple as:

RewriteEngine On
RewriteRule old\.html /new.html [L]

XmisterIS
07-13-2011, 03:56 PM
Ok, I've changed things round a little, I've put the htaccess test in a directory by itself on my development server so I don't pollute other projects.

Here's what I've got:

Let's say the directory I'm working in is:

/var/www/projects/test

And in there is the file new.html

So I've done a copy-and-paste of the code you posted into .htaccess in /var/www/projects/test

The root folder of the local server is /var/www

I enter the following url into the web browser: http://localhost/projects/test/old.html

And I get the file-not-found error.

I know the url is correct because http://localhost/projects/test/new.html displays new.html just as it should.

I know that mod_rewrite is enabled in apache because <?php phpinfo(); ?> shows mod_apache in the apache2handler loaded modules section.

Inigoesdr
07-13-2011, 04:31 PM
Place the code I posted inside of the .htaccess file in your test folder.

XmisterIS
07-13-2011, 04:47 PM
Yep, done that, no joy :(

Inigoesdr
07-13-2011, 05:23 PM
Post the .htaccess you are using. Don't forget you need to adjust the path if you are in a subdirectory.

XmisterIS
07-13-2011, 10:00 PM
Ok,

I've taken your .htaccess as posted, didn't know about the need to change the path, so now I've changed it to this:



RewriteEngine On
RewriteRule /projects/test/old\.html /projects/test/new.html [L]


Still doesn't work!

The trouble is that I know what it's supposed to do, but I just don't know the syntax. I'm missing something vital and painfully simple here!

Inigoesdr
07-13-2011, 11:02 PM
Try leaving the old.html path as it was before("old\.html"). If you're using .htaccess in that directory it is relative.

XmisterIS
07-13-2011, 11:43 PM
Oh dear .. that doesn't work either!

Cags
07-16-2011, 07:28 AM
Try...


RewriteRule .* http://www.google.com [R=302]

... if you don't get redirected to google when requesting old.html then your RewriteRule isn't being parsed. Which probably means you need either FollowSymLinks or AllowOverride directives.

XmisterIS
07-20-2011, 11:14 AM
No, your redirect to google isn't working, although from what you've written it seems you have some good idea as to why ... please could you elaborate? Thanks :)

EDIT:

Ok, so I've had a search on Google for AllowOverride and FollowSymLinks.

Here's my test file as it stands now (still not working!), I've put it in the root directory (/var/www)
AllowOverride All
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule .* http://www.google.com [R=302]



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum