1

I want to remove index.php from url using htaccess. Code Example:

Options +FollowSymlinks
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

For example : If my url https://url.com/index.php then how to make it https://url.com ?.

And the 2nd question is, if someone types https://url.com/directory which is contained non-index, then how to redirect them to the main domain without index.php ?

I am using simple single index file at root not a framework. and using cloudflare dns.

When i replaced last line with RewriteRule ^ %1 [R=301,L] then working.

For example : https://url.com/demo or https://url.com/demo/demo1 (not exists directory) then it redirect to https://url.com without index.php.

But when the url is https://url.com/index.php , it still showing the same url https://url.com/index.php . How to remove index.php?

4
  • Possible duplicate of htaccess remove index.php from url Commented May 22, 2018 at 10:22
  • Not worked for me. Commented May 22, 2018 at 10:30
  • @Hiptop are you using any framework? Commented May 22, 2018 at 11:19
  • No simple one page index file. Commented May 22, 2018 at 11:21

5 Answers 5

2

You may use these rules in site root .htaccess:

Options +FollowSymlinks -Indexes
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ %1 [L,R=301,NE]
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ %1 [L,R=301,NE]
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for you suggest. But i just edited your code, which is working for me.
1

In your project root please create or put .htaccess file. And add following lines.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

Comments

0
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]

6 Comments

check rewrite module is enabled?
Yes rewrite module enabled.
.htaccess and index.php is in same path?
Yes in same path.
it may be issue in your local server, check in live server
|
0
RewriteEngine on
RewriteBase /Projectname
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

3 Comments

deploy on server it will work. may be in local not work, which one you using xamp or wamp ?
do you remove index.php from config file ? $config['index_page'] = ''; $config['uri_protocol'] = 'REQUEST_URI';
Change in config file as upper comment. all the best, i m sure it will work
0

if Use CodeIgniter

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /ProjectName/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>

Else

    <IfModule mod_rewrite.c>
    RewriteEngine On

    # Send would-be 404 requests to Craft
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
    RewriteRule (.+) index.php?p=$1 [QSA,L]
</IfModule>

This is the basic rule to hide index.php from the URL. Put this in your root .htaccess file.

mod_rewrite must be enabled with PHP and this will work for the PHP version higher than 5.2.6.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteEngine On RewriteBase /

# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.