Hide index. php

Source: Internet
Author: User
Hide index. php hide index. php

I. codeigniter

Like many php frameworks, codeigniter has a single entry index. php, which looks unfriendly from the url. Apache rewirte can be used to hide and implement pseudo URLs.

Open config. php in system \ application \ config under codeigniter

Find $ config ['index _ page'] = "index. php"; change to $ config ['index _ page'] = "";

Modify the configuration file httpd. conf in apache conf.

# LoadModule rewrite_module modules/mod_rewrite.so

Remove the # above #. (Enable the change function)

Find


#
# Possible values for the Options directive are "None", "All ",
# Or any combination:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be 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 may be 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 this server.
#
Order allow, deny
Allow from all

Change AllowOverride None to AllowOverride All.

In the same-level Directory of the project, create the. htaccess file as follows:

RewriteEngine On
RewriteCond % {REQUEST_FILENAME }! -F
RewriteCond % {REQUEST_FILENAME }! -D
RewriteCond $1! ^ (Index \. php | images | robots \. txt)
RewriteRule ^ (. *) $/seam/index. php/$1 [L]

The connection can be different from index. php.


II. ThinkPHP

Remove index. php from the URL

ThinkPHP, as a PHP framework, is a single portal, so its original URL is not so friendly. However, ThinkPHP provides various mechanisms to customize the desired URL format. in combination with the Apache. htaccess file, ThinkPHP can also customize a user-friendly and SEO-friendly URL address.

The. htaccess file is a configuration file on the Apache server. it is responsible for the webpage configuration under the relevant directory. We can use the Rewrite rules of the. htaccess file to hide the index. php file (that is, the entry file) in the ThinkPHP URL. this is also the first step of the pseudo-static ThinkPHP URL.

For example, the original URL is:

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

After removing 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/operation name [/variable parameter.

Change Apache httpd. conf configuration file

Tip: If the configuration is performed on the VM provider, configure steps 3 and 4 directly, because the space supporting. htaccess has been configured in the previous two steps.

Open the Apache configuration file httpd. conf in the editor (the file is located in the Apache installation directory Apache2conf) and follow the steps below to modify the file ,.

I. loaded mod_rewrite.so

Confirm that the mod_rewrite.so module is loaded (remove the # before the following configuration ):

LoadModule rewrite_module modules/mod_rewrite.so

II. change AllowOverride configuration

Change the directory for reading the. htaccess file and comment out the original Directory:

#

Change AllowOverride None to AllowOverride FileInfo Options. the changed configuration is as follows:

#

AllowOverride FileInfo Options

. Htaccess is controlled based on directories, This statement indicates that the Directory of the. htaccess file needs to be read and configured according to the actual Apache parsing directory. If the VM provides. htaccess control, it is generally configured.

3. add Rewrite Rules for. htaccess files

Create a. htaccess file in the directory where index. php needs to be hidden (E:/html/myapp in this tutorial, that is, the directory where the entry file is located) and write the following rule code:

RewriteEngine on

# Do not display index. php

RewriteCond % {REQUEST_FILENAME }! -D

RewriteCond % {REQUEST_FILENAME }! -F

RewriteRule ^ (. *) $ index. php/$1 [QSA, PT, L]

If the website already has a. htaccess file, add the configuration rules for this section. If the file cannot be created (cannot be created on Windows), you can download the file from this site. However, this file only configures rules for hiding index. php. Click here to download the file.

4. change the project configuration file

Edit the project configuration file Conf/config. php and set the URL mode to 2 (Rewrite mode ):

'URL _ model' => 2,

So far, the configuration has been completed. After saving the configuration files, restart the Apache server and delete the project cache files under the Runtime Directory. then, access and hide the index. php address in the browser to test whether the files are successful:

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

If the access is successful, you can use the Rewrite rules of the Apache. htaccess file to hide the configuration of the index. php entry file.

Attachment list

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.