简体   繁体   English

在 Codeigniter 中重命名 URL

[英]Rename URL in Codeigniter

I want to remove /public/index.php from my Codeigniter and Bonfire project URLs..我想从我的/public/index.php和 Bonfire 项目 URL 中删除/public/index.php ..

My current URL: http://localhost/public/index.php/page Desired URL: http://localhost/page我当前的网址: http://localhost/public/index.php/page想要的网址: http://localhost/page

but I want the paths for link and images and robots intact!但我希望链接、图像和机器人的路径完好无损! How does one do that?如何做到这一点? Any good resources for working with .htaccess?任何使用 .htaccess 的好资源?

Try reading CodeIgniter URLs , subsection 'Removing the index.php file':尝试阅读CodeIgniter URLs 中的“删除 index.php 文件”小节:

in the .htaccess在 .htaccess 中

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

in the config.php :在 config.php 中:

$config['index_page'] = '';

can you try this?你能试试这个吗?

RewriteEngine On

RewriteBase /



#Removes access to the system folder by users.

#Additionally this will allow you to create a System.php controller,

#previously this would not have been possible.

#'system' can be replaced if you have renamed your system folder.

RewriteCond %{REQUEST_URI} ^system.*

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



#Checks to see if the user is attempting to access a valid file,

#such as an image or css document, if this isn't true it sends the

#request to index.php

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

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

this works fine on my end这对我来说很好用

I think you have to take following steps:我认为您必须采取以下步骤:

  1. Shift your .htaccess file from application to root directory将您的 .htaccess 文件从应用程序转移到根目录

  2. Remove/comment old code (using #) in old file and paste below code删除/注释旧文件中的旧代码(使用#)并粘贴到下面的代码中

RewriteEngine on #RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php?/$0 [PT,L] RewriteRule ^/?ajax/(.*)$ ajax.php?$1 [NC,QSA,L] RewriteEngine on #RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php?/$0 [PT,L] RewriteRule ^/?ajax/(.*)$ ajax.php? $1 [NC,QSA,L]

  1. Remove index.php from config file against $config['index_page'] like below $config['index_page'] = '';针对 $config['index_page'] 从配置文件中删除 index.php,如下所示 $config['index_page'] = '';

  2. Then activate rewrite module from Apache然后从Apache激活重写模块

It should work for you.它应该适合你。

You copy the .htaccess file from application i thought into your basedir.您将 .htaccess 文件从我认为的应用程序复制到您的 basedir 中。

Or add a new .htaccess to your basedir.或者将新的 .htaccess 添加到您的 basedir。

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM