Hide index.php

Source: Internet
Author: User
Tags php framework codeigniter
Hide index.php

First, CodeIgniter

CodeIgniter, like many PHP frameworks, has a single entry index.php that looks unfriendly from the URL. Through Apache's Rewirte, it can be hidden and implemented pseudo-URLs.

Open the config.php in System\application\config under CodeIgniter

Find $config[' index_page '] = "index.php"; instead $config [' index_page '] = "";

Modify the configuration file under Apache Conf httpd.conf

# LoadModule Rewrite_module modules/mod_rewrite.so

Remove the # above. (Turn on Change function)

Found it


#
# Possible values for the Options directive is "None", "all",
# or any combination of:
# Indexes includes followsymlinks symlinksifownermatch execcgi multiviews
#
# Note that "MultiViews" must is named *explicitly*---"Options all"
# doesn ' t give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks

#
# AllowOverride Controls What directives is placed in. htaccess files.
# It can be ' all ', ' None ', or any combination of the keywords:
# Options FileInfo authconfig Limit
#
AllowOverride None

#
# Controls who can get stuff from the this server.
#
Order Allow,deny
Allow from all

Change allowoverride None to allowoverride all

Under the project's sibling directory, create the. htaccess file with the following contents

Rewriteengine on
Rewritecond%{request_filename}!-f
Rewritecond%{request_filename}!-d
Rewritecond $!^ (index\.php|images|robots\.txt)
Rewriterule ^ (. *) $/seam/index.php/$1 [L]

The connection can be no more than a index.php


Second, thinkphp

Remove the index.php from the URL

Thinkphp as a PHP framework, is a single entry, then its original URL is not so friendly. But thinkphp provides a variety of mechanisms to customize the desired URL format, in conjunction with Apache. htaccess files, it is possible to customize a more user-friendly SEO URL address.

The. htaccess file is a configuration file in the Apache server that is responsible for the Web page configuration under the relevant directory. We can use the Rewrite rules of the. htaccess file to hide the index.php file in the thinkphp URL (that is, the portal file), which is also the first step of thinkphp URL pseudo-static.

For example, the original URL is:

Http://127.0.0.1/index.php/Index/insert

After removing the index.php, it becomes:

Http://127.0.0.1/Index/insert

As a result, it becomes a common URL format of http://server address/Application module name/action name [/variable parameter].

Change Apache httpd.conf configuration file

Tip: If you are configuring in a virtual host, configure the third to fourth step directly because the support. htaccess space has been configured for the first two steps.

Use the editor to open the Apache configuration file httpd.conf (the file is located in the Apache installation directory apache2conf) and follow the steps below to modify it.

First, load the mod_rewrite.so

Verify that the mod_rewrite.so module is loaded (remove the # number before configuration):

LoadModule Rewrite_module modules/mod_rewrite.so

Second, change the allowoverride configuration

Change the directory where the. htaccess file needs to be read and comment out the original directory:

#

Change allowoverride None to allowoverride FileInfo Options, and the changed configuration is as follows:

#

AllowOverride FileInfo Options

The. htaccess is directory-based, which means that the directory to which the . htaccess file needs to be read is configured according to the actual specific Apache parsing directory. If the virtual host is provided with. htaccess control, it is generally configured.

Iii. Add. htaccess file Rewrite rules

Create the. htaccess file in the directory where you want to hide index.php (in this tutorial, the directory where the portal file is located), and write the following rule code:

Rewriteengine on

#不显示index. php

Rewritecond%{request_filename}!-d

Rewritecond%{request_filename}!-f

Rewriterule ^ (. *) $ index.php/$1 [qsa,pt,l]

If the site already has a. htaccess file, add the section configuration rule inside. If the file cannot be created (the Windows platform cannot be created), you can download the file from this site, but the file is only configured with hidden index.php rules, click here to download.

Iv. changing the project configuration file

Edit the Project Profile conf/config.php, configure the URL pattern to 2 (rewrite mode):

' Url_model ' =>2,

At this point, the individual configurations are complete. After saving each configuration file, restart the Apache server and delete the project cache file under the Runtime directory, and the address test after the browser accesses the hidden index.php is successful:

Http://127.0.0.1/html/myapp/Index/index

If the access is successful, then the configuration of the index.php portal file using the Rewrite rules of the Apache. htaccess file is successful.

List of attachments

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.