【问题标题】:Error 404: The links on my website don't work, only index (using Codeigniter & .htaccess)错误 404:我网站上的链接不起作用,只有索引(使用 Codeigniter 和 .htaccess)
【发布时间】:2017-06-11 18:31:35
【问题描述】:

我在 Apache 服务器上托管我的网站 http://tstspanama.com/。它是使用 PHP 框架 Codeigniter 创建的。我只能看到主页,其他什么都看不到,链接失效了。

如果我想去http://tstspanama.com/servicios,我会得到:

找不到

在此服务器上找不到请求的 URL /servicios

有人知道如何解决这个问题吗?我附上所有重要的代码。

关于应用程序配置 (/var/www/tsts/application/config/config.php)

$config['base_url']     = isset($_SERVER['REQUEST_URI']) && $_SERVER['HTTP_HOST'] != 'localhost' ? 'http://'.$_SERVER['HTTP_HOST'].'/' : 'http://www.tstspanama.com/';

$config['index_page'] = '';

$config['uri_protocol'] = 'AUTO';

在我的 .htaccess 中

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /tsts/
    RewriteCond $1 !^(index\.php|assets|images|css|js|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    ErrorDocument 404 /index.php
</IfModule>

<ifModule mod_php5.c>
    php_value default_charset utf-8
</ifModule>

php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on

在 /etc/apache2/sites-available/www.tstspanama.com

<VirtualHost *:80>
    ServerName www.tstspanama.com
    ServerAlias tstspanama.com

    DocumentRoot /var/www/tsts
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>

    <Directory /var/www/tsts>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log
    # Possible values include: debug, info, notice, warn, error,
    # crit, alert, emerg.
    LogLevel error
    CustomLog /var/log/apache2/access.log combined
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
</VirtualHost>

【问题讨论】:

  • 以后,永远不要发布图片来代替错误消息或代码。本网站的搜索引擎只索引文本。已编辑。

标签: php apache .htaccess codeigniter routing


【解决方案1】:

如果你添加RewriteBase,url考虑用它,所以删除它或使用/

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond $1 !^(index\.php|assets|images|css|js|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    ErrorDocument 404 /index.php
</IfModule>

<ifModule mod_php5.c>
    php_value default_charset utf-8
</ifModule>

php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on

【讨论】:

  • 我实际上拥有的是 RewriteBase /tsts/ 。我为什么要改变它?我不太明白这是如何工作的
  • 如果你的 .htaccess 与 index.php 同目录,则不需要。 RewriteBase 为您的路径添加前缀。换句话说,当尝试加载 tstspanama.com/servicios 并且您有 RewriteBase /tsts/ 时,apache 尝试从当前目录 + /tsts/ 文件夹加载 index.php。你试试看?
猜你喜欢
  • 2013-07-28
  • 2013-06-02
  • 1970-01-01
  • 1970-01-01
  • 2012-10-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-02
  • 2014-10-20
相关资源
最近更新 更多