Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jun 2010
    Posts
    302
    Thanks
    68
    Thanked 8 Times in 8 Posts

    Getting started with .htaccess on Debian Etch

    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 ...

    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
    Last edited by XmisterIS; 07-13-2011 at 04:14 PM.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    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:
    Code:
    RewriteEngine On
    RewriteRule old\.html /new.html [L]

  • #3
    Regular Coder
    Join Date
    Jun 2010
    Posts
    302
    Thanks
    68
    Thanked 8 Times in 8 Posts
    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.
    Last edited by XmisterIS; 07-13-2011 at 05:07 PM.

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Place the code I posted inside of the .htaccess file in your test folder.

  • #5
    Regular Coder
    Join Date
    Jun 2010
    Posts
    302
    Thanks
    68
    Thanked 8 Times in 8 Posts
    Yep, done that, no joy

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Post the .htaccess you are using. Don't forget you need to adjust the path if you are in a subdirectory.

  • #7
    Regular Coder
    Join Date
    Jun 2010
    Posts
    302
    Thanks
    68
    Thanked 8 Times in 8 Posts
    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:

    Code:
    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!

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Try leaving the old.html path as it was before("old\.html"). If you're using .htaccess in that directory it is relative.

  • #9
    Regular Coder
    Join Date
    Jun 2010
    Posts
    302
    Thanks
    68
    Thanked 8 Times in 8 Posts
    Oh dear .. that doesn't work either!

  • #10
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Try...

    Code:
    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.

  • #11
    Regular Coder
    Join Date
    Jun 2010
    Posts
    302
    Thanks
    68
    Thanked 8 Times in 8 Posts
    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)
    Code:
    AllowOverride All
    Options +FollowSymLinks
    Options +Indexes
    RewriteEngine On
    RewriteRule .* http://www.google.com [R=302]
    Last edited by XmisterIS; 07-20-2011 at 12:19 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •