【问题标题】:CodeIgniter project .htaccess issueCodeIgniter 项目 .htaccess 问题
【发布时间】:2017-06-03 15:46:15
【问题描述】:

我想在 GoDaddy 主机上安装一个 codeigniter 项目。

我已按照 CodeIgniter Wiki 中的 Godaddy Installation Tips 说明进行操作。

在 config.php 中

$config['index_page'] = "index.php?";
$config['uri_protocol'] = "QUERY_STRING";

在 .htaccess 中

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?$1 [L]

我可以访问所有内容

http://yourdomain.com/controller/action/etc

但是

当我在 url 中有获取参数时

http://yourdomain.com/controller/action/etc?id=1

.htaccess 去掉参数 ?id=1 所以

http://yourdomain.com/controller/action/etc?id=1

成为

http://yourdomain.com/controller/action/etc

【问题讨论】:

  • 我不明白你为什么使用查询字符串,你已经可以选择漂亮的网址
  • 你可以像http://yourdomain.com/controller/action/etc/1一样访问
  • 查询字符串在项目规范中

标签: php .htaccess codeigniter


【解决方案1】:

.htaccess 中试试这个代码:

DirectoryIndex index.php
# Turn on URL rewriting
RewriteEngine On

# If your website begins from a folder e.g localhost/my_project then 
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is

RewriteBase /


# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)

# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]

# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|opensearch\.xml|favicon\.ico|assets|forums)

# No rewriting
RewriteRule ^(.*)$ - [PT,L]

# Rewrite to index.php/URL
RewriteCond %{REQUEST_URI} !^(.+)\.(js|css|gif|png|jpg|jpeg|bmp|swf|txt|xml|htc|pdf|xls|doc|ico)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [PT,L]

我在其中一个项目中使用了它,它在那里工作......

【讨论】:

    猜你喜欢
    • 2011-10-04
    • 1970-01-01
    • 2011-07-25
    • 2020-06-18
    • 1970-01-01
    • 2012-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多