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 6 of 6
  1. #1
    New Coder
    Join Date
    Nov 2009
    Posts
    61
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Redirect to directory index.php

    Hi All,

    I am trying to re-direct my directory URLs to the index.php file. As an example from http://www.domain.com/directory/ to http://www.domain.com/directory/index.php

    I have the following code, but it doesn't appear to be working correctly, can anyone help please?

    Code:
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Why would you want to do that? If you don't provide an explicit script to run, it will automatically run the index.php. If it does not have an index (php, html, etc in order specified by the directives), but does have options +indexes, you'll get an indexed view. Without the option +indexes, and still no index script, than instead you get a 404.

    Or are you intending it to go from /directory to index.php?q=directory? If that's the case, that's doable, and should actually match the code you have. The only potential block is if /directory/ actually exists, in which case it won't follow the rewrite directive since one of the conditions is that its not a directory.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Apr 2013
    Posts
    39
    Thanks
    2
    Thanked 2 Times in 2 Posts
    since you want to redirect all your directory to index page just use something like this


    #301 Redirect Entire Old directories
    RedirectMatch 301 pp(.*) http://www.mysite.com/index.php$1

    if you need more htaccess you can check my signature

  • #4
    New Coder
    Join Date
    Nov 2009
    Posts
    61
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Hi Fou-Lu,

    I require this for SEO purposes as http://www.domain.com/directory/ and http://www.domain.com/directory/index.php both display the same content which makes it duplicate content which is bad for SEO

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Its not duplicate content; /directory/ is equivalent to /directory/index.php since they both serve the same script, assuming that the index.php is designated as the default index script. So they both go to exactly the same script, so I'm not sure I follow where this is a problem?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    New Coder
    Join Date
    Feb 2013
    Location
    Liverpool
    Posts
    70
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Just make sure your DirectoryIndex is set to index.php and it'll automatically show you the yoursite.com/index.php page when you hit the site. Just put this in your .htaccess file

    Code:
    DirectoryIndex index.php
    Let me know if that works!
    Working for Edge Three Sixty doing Drupal Development


  •  

    Posting Permissions

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