www.webdeveloper.com
Results 1 to 5 of 5

Thread: .htaccess - redirect index.php and non www

  1. #1
    Join Date
    Jan 2009
    Posts
    87

    .htaccess - redirect index.php and non www

    Hi,

    I would like my .htaccess file to redirect the following urls to:

    http://www.mysite.com/

    The urls to redirect are:

    http://www.mysite.com/index.php
    http://mysite.com
    http://mysite.com/index.php
    mysite.com

    The code below currently redirects http://www.mysite.com/index.php to http://www.mysite.com/ but i think it also redirects any missing (404) page to http://www.mysite.com/ as well... Anyway any help is greatly appreciated

    Code:
    Options +FollowSymLinks
    DirectoryIndex index.php
     
    RewriteEngine On
    RewriteBase /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
    RewriteRule ^index\.php$ http://www.mysite.com/ [R=301,L]
     
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    Thanks

    Paul

  2. #2
    Join Date
    Mar 2009
    Posts
    452
    hi there, following code causes missing file/directory redirect to index.php
    Code:
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

  3. #3
    Join Date
    Jan 2009
    Posts
    87
    thanks for your reply

    Could you demonstrate how to redirect mysite.com/index.php to www.mysite.com?

    thanks

    paul

  4. #4
    Join Date
    Mar 2009
    Posts
    452
    Code:
    RewriteRule ^index.php$ http://www.mysite.com

  5. #5
    I'm having some what similar problem. What I have set up right now is all non www urls redirect to a www url.

    Problem: Although technically it works, aside from the index page when ever I do not include a www. in the url of a particular page it redirects me to the index.php

    Here is part of my .htaccess file:
    ## Begin - Joomla! core SEF Section.
    #
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    #
    # If the requested path and file is not /index.php and the request
    # has not already been internally rewritten to the index.php script
    RewriteCond %{REQUEST_URI} !^/index\.php
    # and the request is for something within the component folder,
    # or for the site root, or for an extensionless URL, or the
    # requested URL ends with one of the listed extensions
    RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
    # and the requested path and file doesn't directly match a physical file
    RewriteCond %{REQUEST_FILENAME} !-f
    # and the requested path and file doesn't directly match a physical folder
    RewriteCond %{REQUEST_FILENAME} !-d
    # internally rewrite the request to the index.php script
    RewriteRule .* index.php [L]
    #
    ## End - Joomla! core SEF Section.
    RewriteCond %{HTTP_HOST} ^alpineascent.com$
    RewriteRule ^(.*)$ "http\:\/\/www\.alpineascent\.com\/$1" [R=301,L]

    Any help would be greatly appreciated!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles