【问题标题】:Codeigniter .htaccess redirect and hide URL partCodeigniter .htaccess 重定向和隐藏 URL 部分
【发布时间】:2014-11-26 12:04:07
【问题描述】:

我希望有两个 Codeigniter 安装,一个在我的默认根 root/,一个在 root/en。问题出在我的 .htaccess 文件和默认控制器的位置。在我的默认安装中一切正常,我在以下目录中有默认/前端控制器:root/public/index.php 并且我的 .htaccess 看起来像这样,以便从 url 重定向和删除“public”:

RewriteEngine on
RewriteBase /

ReWriteCond %{REQUEST_URI} !public/
ReWriteRule ^(.*)$ public/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php?/$0 [PT,L] 

在根目录下一切正常,服务器自动重定向到root/public/index.php 文件夹并在那里读取“index.php”,.htaccess 然后隐藏 url 的“public/index.php”部分。

如何编写类似的 .htaccess 文件,这样当用户键入 url “sitename/en”时,它会自动重定向到 root/en/public/index.php 并隐藏 public/index.php 部分?

【问题讨论】:

  • 尝试将#2 行编辑为RewriteBase /en

标签: php .htaccess codeigniter mod-rewrite


【解决方案1】:

尝试使用以下任何一种:

RewriteEngine on
RewriteBase /demo/
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

确保 config.php 文件有

$config['base_url'] = "http://".$_SERVER['HTTP_HOST']."/projectname";
$config['uri_protocol'] = 'PATH_INFO';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    • 2015-04-15
    • 2015-12-16
    • 2014-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多