php - 我的 htaccess 正确吗?

标签 php mysql apache

我正在尝试使用 PHP 和 MySQL 构建购物车。现在我正在创建产品详细信息页面。这就是我设置 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 ^([^\.]+)$ $1.php [NC,L]
</IfModule>
<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

我的问题是,如果包含 index.php,我只能访问某个页面。例如,http://localhost/thegamingplace/products/details/1 显示“未找到”错误,但 http://localhost/thegamingplace/index.php/products/details/1 有效。

有人可以看看我的 htaccess 并告诉我我做错了什么吗?

最佳答案

试试这个:

RewriteCond %{REQUEST_URI} !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ index.php/$1 [NC,L]

http://htaccess.mwl.be/ 测试时有效

如果它不起作用,请确保您安装并启用了 mod_rewrite。

关于php - 我的 htaccess 正确吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42753281/

相关文章:

php - MySQL + CodeIgniter + 点击跟踪唯一点击次数和总点击次数

php - 类方法和常规函数之间有什么区别吗?

PHP - 页面加载时显示表单错误警报

mysql - 在mysql中选择一周前的记录

apache - 在提供页面后,HTTP 套接字连接仍处于 TIME_WAIT 状态

php - 启用 PHP Apache2

php - 在 mySQL 查询中使用 MAX() 会产生有问题的结果

mysql - 尝试连接到远程 MySQL 主机(错误 2003)

php - 如果与字符串相比,如何将数组元素移动到顶部?

python - Apache2 mod_wsgi 403 禁止错误