【问题标题】:Shortening URL in Code Igniter在 Codeigniter 中缩短 URL
【发布时间】:2014-06-03 09:36:35
【问题描述】:

我正在为网站开发 CodeIgniter 框架。我上传了我的网站,它可以工作。现在我想做的是制作一些只有几个人知道但仍然容易记住的秘密 URL 快捷方式。我想让 www.mywebsite.com/secretpage 加载我的秘密页面。但是 codeigniter 似乎不允许直接访问文件。我听说我可以使用 .htaccess 使用 url 路由,但它似乎不起作用。

【问题讨论】:

  • 什么似乎不起作用?你有什么尝试粘贴该代码

标签: php .htaccess codeigniter


【解决方案1】:

使用codeigniter Routes http://ellislab.com/codeigniter/user-guide/general/routing.html 可以缩短URLS。添加 url 帮助程序以自动加载。

您无法直接访问 php,因为控制器顶部的代码阻止了它。

举例说明为什么你不能直接访问。

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

如何缩短路线示例。

www.yourdomain.com/secretpage/

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

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

也可以使用 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]

从配置文件中删除 index.php。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多