简体   繁体   English

缩短Code Igniter中的URL

[英]Shortening URL in Code Igniter

I am working on a CodeIgniter framework for a website. 我正在为网站开发CodeIgniter框架。 I uploaded my website and it works. 我上传了网站,并且可以正常工作。 now what I want to do is to make some kind of secret URL shortcut that only several people know but still easy to remember. 现在,我要做的是制作一种秘密的URL快捷方式,只有几个人知道,但仍然很容易记住。 I want to make www.mywebsite.com/secretpage to load up my secret page. 我想创建www.mywebsite.com/secretpage来加载我的秘密页面。 however codeigniter doesn't seems to allow direct access to files. 但是codeigniter似乎不允许直接访问文件。 I heard I can use the url routing using .htaccess but it doesn't seems to work. 我听说我可以通过.htaccess使用url路由,但似乎无法正常工作。

Use the codeigniter Routes http://ellislab.com/codeigniter/user-guide/general/routing.html Can shorten URLS. 使用codeigniter路由http://ellislab.com/codeigniter/user-guide/general/routing.html可以缩短URL。 Add url helper to autoload. 将url助手添加到自动加载。

You can't get direct access to the php because the code at the top of the controller blocks it. 您无法直接访问php,因为控制器顶部的代码阻止了它。

example why you can not get direct access. 为何无法直接访问的示例。

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

How to shorten routes Example. 如何缩短路线示例。

www.yourdomain.com/secretpage/ www.yourdomain.com/secretpage/

$route['secretpage'] = "folder/controller/index";

$route['secretpage'] = "folder/controller/index";

Also use htaccess 也使用htaccess

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

remove the index.php from the config file. 从配置文件中删除index.php。

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

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