我正在尝试使用 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/