user3886174
user3886174

Reputation:

How to load my site without index.php directly

I have a problem. When I go on my site: http://nextgenfocus.com/, content is not properly loaded and I need to add index.php so that all content is displayed. I would like that when that when I run my site in the URL without index.php, it loads directly the index.php without that I need to do it manually.

index.php:

<!DOCTYPE html>
<html lang="en-us">
    <head>
        <meta charset="UTF-8">
        <?php
        if(strpos($_SERVER["REQUEST_URI"], "index.php") !== false) { ?>
        <title>Test - Home</title>
        <?php } ?>
       <?php
        if(strpos($_SERVER["REQUEST_URI"], "downloads") !== false) { ?>
        <title>Test - Downloads</title>
        <?php } ?>
       <?php
        if(strpos($_SERVER["REQUEST_URI"], "help") !== false) { ?>
        <title>Test - Help</title>
        <?php } ?>
        <link href="css/style.css" rel="stylesheet" type="text/css">
        <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <?php include("top_bar.php");?>
        <?php include("container.php");?>
        <?php include("footer.php");?>
    </body>
</html>

Can you help me, please?

Thanks.

Upvotes: 0

Views: 4351

Answers (4)

jned29
jned29

Reputation: 478

Put this code on your .htaccess

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 

.htaccess should go into same folder as your CI’s index.php file.

or try this one..

<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [NC,QSA,L]
</ifModule>

Its possible that .htaccess is not enabled on your site. If you are hosting it yourself, it's easy enough to fix; open your httpd.conf in a text editor, and locate this section..

# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/var/www/htdocs">
#

..locate the line that reads..

AllowOverride None

..and change it to..

AllowOverride All

Restart Apache.

I have this reference .htaccess

Upvotes: 0

ProtoAES256
ProtoAES256

Reputation: 28

This is my WAMP .htaccess file, work hurt trying it, won't ya? :D

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Upvotes: 0

Vennik
Vennik

Reputation: 565

Create a file .htaccess in your home dir. Put this in it:

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

And $_SERVER['REQUEST_URI'] in PHP to get the url.

Upvotes: 2

chiwangc
chiwangc

Reputation: 3577

You can create a text file named .htaccess that contains the following rule, and then place this file at the root of your server.

DirectoryIndex index.php index.html index.htm


So whenever someone visits your webpage at www.example.com, your server try to display the content of index.php to her, if such file doesn't exists, your server will try index.html, and then index.htm and so on.

Upvotes: 1

Related Questions