2012-01-05 60 views
0

这是URL链接时,这上面的URL我想要去我可以做到这一点使用httaccess一个控制器function.Howrediecting到笨控制器使用httaccess

http://rapidsurfing.net/visio/xip8yT 

我的网站在codeigniter.So发展。

这是我httaccces代码

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteRule ^p\/(.*)$ page.php?q=$1 [L] 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.*)$ index.php?admin/index/url=$1 [QSA,L] 
</IfModule> 

url具有价值xip8yT .The admin是控制器的名字和index是该控制器的功能。

但是,当我在地址栏中粘贴url http://rapidsurfing.net/visio/xip8yT它加载404找不到错误。 我的代码中有什么问题或错误? 我的defualt控制器是admin。

回答

1

首先请确保您在routes.php文件中设置了默认控制器。您的问题的完整答案是我与CI合作的方式。 CodeIginter本身建议使用.htaccess将所有请求重定向到您的索引页面和您的默认控制器,这就是您所做的。但是,我建议使用这段代码:

<IfModule mod_rewrite.c> 

    RewriteEngine On 
    RewriteBase /yourbasefoldername 

    ### Canonicalize codeigniter URLs 

    # If your default controller is something other than 
    # "welcome" you should probably change this 
    RewriteRule ^(yourdefaultcontrollername(/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://localhost/dfgamez/$1 [L,R=301] 

    # Enforce NO www 
    # RewriteCond %{HTTP_HOST} ^www [NC] 
    # RewriteRule ^(.*)$ http://localhost/dfgamez/$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] 

</IfModule> 

<IfModule !mod_rewrite.c> 

    # Without mod_rewrite, route 404's to the front controller 
    ErrorDocument 404 /index.php 

</IfModule> 

只要你将网站地址后,每一个斜杠得到你index函数的参数。

平安!

+0

我还设置了我的默认控制器作为管理员 – Kichu 2012-01-05 10:03:06

+0

什么都不会发生相同的显示 – Kichu 2012-01-05 10:06:24

+0

它是在您的localhost或主要主机?确定你的应用程序是否在主要主机上,像这样删除RewriteBase:'RewriteBase /'没有任何名字。如果您编写了错误代码或未正确配置CI的一部分,则必须发生该错误。顺便说一句,在'config.php'文件中设置'$ config ['base_url']'为空。 – MahanGM 2012-01-05 11:59:38