.htaccess redirect index.php to /
Asked Answered
T

3

7

I would like to hide the index.php page and just show the domain.

Is this possible with .htaccess?

RewriteRule ^index\.php/?$ / [L,R=301,NC]

Also tried:

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.php HTTP/
RewriteRule ^index.php$ http://example.com/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

index.php still shows

Thelmathem answered 6/2, 2013 at 16:29 Comment(0)
J
11

Try, It works for me! Make sure your have AllowOverride All set in httpd.conf

RewriteEngine On 

    RewriteCond %{REQUEST_URI} index\.php
    RewriteRule ^(.*)index\.php$ /$1/ [R=301,L]

There is a regex issue in your rules, I have modified your rules and it works for me:

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} index\.php
RewriteRule ^index\.php$ http://example\.com/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index\.php [L]
Jonme answered 6/2, 2013 at 16:43 Comment(3)
nope. could browsers always show the index.php and not redirect to just the domain?Thelmathem
Can you post your .htaccess file.Jonme
the redirect is working, but also adding an trailing slash, the result is example.com// instead of example.comIdaho
V
6
RewriteRule ^(.*)index\.(html|php)$ http://%{HTTP_HOST}/$1 [R=301,L]
Vassallo answered 15/7, 2014 at 5:30 Comment(0)
L
1

You can rewrite '/index.php' through .htaccess like this:

# Remove /index.php from all urls
RewriteRule ^(.+)/index\.php$ /$1 [R=302,L]
Lidialidice answered 4/5, 2021 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.