【发布时间】:2015-05-03 17:59:35
【问题描述】:
我已经在生产环境中上传了我在框架 CodeIgniter 上制作的 PHP 网站文件。尽管我更改了 .htaccess 文件及其依赖项(配置等),但仍然出现错误 404,就好像服务器无法访问控制器文件一样。这是我第一次尝试将网站投入生产,有什么想法吗?
.htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
### Canonicalize codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# Enforce www
# If you have subdomains, you can add them to
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]
# Enforce NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
###
# 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]
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
config.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$config['base_url'] = 'http://mywebsite.com';
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'REQUEST_URI';
$config['url_suffix'] = '';
【问题讨论】:
-
请提供有关问题的更多详细信息。例如您的代码和您尝试上传到的路径。
-
请提供一些代码和你的路径。这将有助于我们帮助您。
-
服务器上的 mod_rewrite 是否处于活动状态?如果是,请确保 .htaccess 文件具有 Options -Multiviews +FollowSymlinks 指令,并且您可以覆盖选项。
标签: php .htaccess codeigniter mod-rewrite production