Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Apache, redirect

  1. #1
    Join Date
    Apr 2013
    Beans
    7

    Apache, redirect

    I'm messing around with Apache and I was wondering how to redirect Apache from it's Index.html file to another file temporarily. I want to be able to go to 127.0.0.1 (or localhost) on my browser and for it to take me to a file I created called Index2.html (Also in /var/www). I then want to be able to delete the Index2.html file and have it go back to Index.html without making excess changes to Index.html other than to redirect it.

  2. #2
    Join Date
    Apr 2013
    Beans
    21

    Re: Need help with Apache

    i'm going to say that is the DirectoryIndex parameter in the httpd.conf file. I don't recall exactly where ubuntu stores it (/etc/httpd/conf, most likely, but it could be under /etc/apache2). Anyway, more info here: http://www.cyberciti.biz/faq/apache-...han-indexhtml/

  3. #3
    Join Date
    Jul 2005
    Location
    Melbourne, Australia
    Beans
    18
    Distro
    Ubuntu 6.10 Edgy

    Re: Need help with Apache

    If you want to redirect whenever the 'index2.html' file is present, for example while performing maintenance on your site, then you could use a rewrite rule like this (put it in your apache config file):

    Code:
    RewriteEngine On
    RewriteCond %{DOCUMENT_ROOT}/index2.html -f
    RewriteRule ^/index.html$ /index2.html [R]
    What these lines do is:
    1. Enable the rewrite engine
    2. Determine if index2.html exists in the document root (usually /var/www/html), if it does exist, then process the rewrite rules below
    3. Rewrite requests for /index.html to /index2.html, and the R bit at the end says to do this using a redirect

  4. #4
    Join Date
    Apr 2013
    Beans
    7

    Re: Need help with Apache

    Thank you for responding and I'm sorry it took me so long to respond. Where in my apache.conf file do I put the rewrite code?

  5. #5
    Join Date
    Sep 2006
    Beans
    7,955
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Need help with Apache

    The rewrite rules can go almost anywhere per vhost in <VirtualHost> or per directory in <Directory> etc.

    You do need to have the module turned on first before it will work.

    Code:
    sudo a2enmod rewrite
    See the rewrite guide for full details.
    The Truth Shall Make Ye Fret.

  6. #6
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    9,596
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: Need help with Apache

    I think it's a lot easier to create symlinks, e.g., "ln -s index2.html index.html". Just make sure you have "Options FollowSymLinks" included in the <Directory> stanza for that directory.

    Of course, you realize that you can access index2.html directly by using the URL http://localhost/index2.html, right?
    If you ask for help, please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  7. #7
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Need help with Apache

    Quote Originally Posted by SeijiSensei View Post
    I think it's a lot easier to create symlinks, e.g., "ln -s index2.html index.html". Just make sure you have "Options FollowSymLinks" included in the <Directory> stanza for that directory.

    Of course, you realize that you can access index2.html directly by using the URL http://localhost/index2.html, right?
    I would have to agree, but if you symlink index.html to index2.html, what's the point of having index2.html instead of just using index.html ?
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  8. #8
    Join Date
    Nov 2008
    Location
    Metro Boston
    Beans
    9,596
    Distro
    Kubuntu 14.04 Trusty Tahr

    Re: Need help with Apache

    Sometimes I'll have two different versions of the file, in my case, say index1.php and index2.php. It makes it easy to switch from one to the other if I use a symlink to index.php.

    The OP wanted an easy way to switch from one index file to another. As I said, I'd just avoid the problem by using the appropriate URL and accessing the correct file directly.
    If you ask for help, please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  9. #9
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Apache, redirect

    Ah, that makes sense. Thanks!
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  10. #10
    Join Date
    Apr 2013
    Beans
    7

    Re: Apache, redirect

    It still does not work. I have enabled mod rewrite and posted the rewrite rules into the apache.conf file in different locations. I restart apache after each change I make and when I go to my browser and type in 127.0.0.1 it still takes me to the index.html page instead of the index2.html

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

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