簡體   English   中英

如何在Ubuntu 14.04 Lamp Stack Server上的Codeigniter中設置.htaccess

[英]How to setup .htaccess In Codeigniter on Ubuntu 14.04 Lamp Stack Server

我不知道如何進行,我一步一步檢查了許多教程,但沒有成功,我開始認為這是我的apache運行不正常的原因。

我不是服務器人員,並且總是被這些東西所困擾,我的站點在本地運行良好,但是將其傳輸到服務器后,問題就開始了。

如果您能幫助我,我將不勝感激。

/etc/apache2/sites-available
mysite.com.conf
   # domain: mysite.com
    # public: /var/www/mysite.com/public_html/

    <VirtualHost *:80>
    #error 403
        <Directory "/var/www/mysite.com/public_html/blog">
            Options FollowSymLinks
            Require all granted
            AllowOverride None
            Require all granted
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
            <IfModule mod_rewrite.c>
              RewriteEngine On
              RewriteBase /blog/
              RewriteRule ^index\.php$ - [L]
              RewriteCond %{REQUEST_FILENAME} !-f
              RewriteCond %{REQUEST_FILENAME} !-d
              RewriteRule . /blog/index.php [L]
            </IfModule>
        </Directory>

         <Directory "/var/www/mysite.com/public_html/">
            Options FollowSymLinks
            Require all granted
            AllowOverride All
            Require all granted
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
        </Directory>

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

      # Index file and Document Root (where the public files are located)
      DirectoryIndex index.html index.php
      DocumentRoot /var/www/mysite.com/public_html
      # Log file locations
      LogLevel warn
      ErrorLog  /var/www/mysite.com/log/error.log
      CustomLog /var/www/mysite.com/log/access.log combined
    </VirtualHost>

在/ etc / apache2的/站點可用

000-default.conf

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    DocumentRoot /var/www/mysite
#for the error 403

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

/ etc / apache2 apache2.conf

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

應用/配置/ config.php中

$config['base_url'] = '';
$config['index_page'] = '';

我的根目錄中的.htaccess文件

 RewriteEngine on
   RewriteCond $1 !^(index\.php|assets|robots\.txt)
   RewriteRule ^(.*)$ index.php?/$1 [L]

保持example.com.conf如此簡單:

<VirtualHost *:80>
ServerName      example.com
ServerAlias     www.example.com
DocumentRoot    /var/www/example.com/public_html
</VirtualHost>

保存並關閉此文件后,請確保通過鍵入以下內容啟用VirtualHost:sudo a2ensite example.com.conf

現在重新啟動apache,sudo服務apache2重新啟動

這就是您在/var/www/example.com/public_html中的.htaccess應該是這樣的:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

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

在您的application / config / config.php中

$config['base_url'] = 'http://www.example.com/';

嘗試這些設置,讓我知道它是否適合您。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM