基本的HTACCESS问题

时间:2013-10-16 14:30:43

标签: php regex apache .htaccess mod-rewrite

我在我的系统上安装了WAMPSERVER。在htdocs文件夹中,我的项目文件夹名为'online-store'

所以要访问我的项目我写

http://localhost/online-store

我想要所有的请求,比如

http://locahost/online-store/products/2 or http://localhost/online-store/products/ 

重定向到api.php。 我已经为此写了htaccess代码,但它说

/online-store/products url was not found on the system.

我正在重写htaccess以使其成为一个宁静的API。 以下是我的HTACCESS代码。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ api.php?request=$1 [QSA,NC,L]
</IfModule>

2 个答案:

答案 0 :(得分:1)

确保将此代码放在htdocs/online-store/.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /online-store/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ api.php?request=$1 [QSA,L]
</IfModule>

答案 1 :(得分:1)

您需要更改httpd.conf中的代码

wampdir / bin中/阿帕奇/ apache2.x.x。/ CONF / httpd.conf中

<FilesMatch "^\.ht">
    Order allow,deny
    Allow from all
    Satisfy All
</FilesMatch>