[英]codeigniter - what's wrong with my htaccess?
I'm trying to build a shopping cart locally using PHP & MySQL. 我正在尝试使用PHP和MySQL在本地构建购物车。 My main directory for my site is /Library/WebServer/Documents. 我网站的主目录是/ Library / WebServer / Documents。 I tried to set it up so that I can access localhost/project without the index.php. 我试图进行设置,以便无需index.php就可以访问localhost / project。
Here's my htaccess: 这是我的htaccess:
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
My config code (extracted, not the whole thing): 我的配置代码(提取的不是全部):
$config['base_url'] = 'http://localhost/project/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Apparently there's an error with this. 显然有一个错误。 Even though I managed to access localhost/project without index.php, I can't view pages generated by my controller code (ex. if I try to go to localhost/project/welcome I get this error message: 'The requested URL /project/welcome was not found on this server.' localhost/project/welcome should take me to the Welcome.php page under my controllers folder. 即使我在没有index.php的情况下成功访问了localhost / project,也无法查看由控制器代码生成的页面(例如,如果尝试转到localhost / project / welcome,则会收到此错误消息: “请求的URL /在此服务器上找不到 project / welcome。'localhost / project / welcome应该带我到我的controllers文件夹下的Welcome.php页面。
Here's a snapshot of the file structure 这是文件结构的快照
Can someone explain to me what's wrong with my code? 有人可以向我解释我的代码有什么问题吗?
Do you mean without .php? 你是说没有.php吗?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
OR 要么
remove this DirectoryIndex index.php! 删除此DirectoryIndex index.php! It sets the index.php behind the url 它在URL后面设置index.php
Use this .htaccess: 使用此.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#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]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
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>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.