从子域codeigniter 3中删除index.php

时间:2015-10-17 09:32:53

标签: codeigniter

我已经查看了一些Stack Overflow问题,用于从子域 url中删除index.php,请不要将其标记为重复。

Stack Overflow我已阅读并尝试过。

CodeIgniter in subdomain folder, removing the index.php from address

remove index.php of codeigniter subdomains

Removing index.php and handling subdomains of two Codeigniter sites, when one within the other

但似乎无效我正在使用 WAMP Codeigniter 3 并启用了MOD Rewrite。我也使用虚拟主机。

  

问题:什么是最适合子域的htacces,以便我可以删除index.php?

页面错误:

codeigniter 500 internal server error

我的文件夹结构

www / 
www / codeigniter / cms-1 <-- This is main project
www / codeigniter / cms-1 / application

www / codeigniter / cms-1 / cms-2 <-- This is sub domain 
www / codeigniter / cms-1 / cms-2 / index.php
www / codeigniter / cms-1 / cms-2 / .htaccess

www / codeigniter / cms-1 / image / 
www / codeigniter / cms-1 / system 
www / codeigniter / cms-1 / .htaccess
www / codeigniter / cms-1 / index.php

当我在WAMP上有URL时,如下所示。

  

http://www.cms-2.cms-1.com/information/information/3

但是当我有index.php工作时。

  

http://www.cms-2.cms-1.com/index.php/information/information/3

我已移除application > config > config.php

$config['index_page'] = '';
  

下面的.htaccess位于主目录上,可以正常使用   域。

Options +FollowSymLinks

# Prevent Directoy listing
Options -Indexes

# Prevent Direct Access to files

<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
    Order deny,allow
    Deny from all
</FilesMatch>

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

2 个答案:

答案 0 :(得分:4)

使用此:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  ErrorDocument 404 /index.php
</IfModule>

答案 1 :(得分:1)

替换你的base_url

if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on"){$ssl_set = "s";} else{$ssl_set = "";}
$config['base_url'] = 'http'.$ssl_set.'://'.$_SERVER['HTTP_HOST'];

在.htaccess

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

如需更多阅读此http://w3code.in/2015/10/how-to-make-multiple-websitesubdomain-of-your-main-site-in-codeigniter-with-same-code-and-database-dynamically/