干净的URL .htaccess问题 - 找不到页面

时间:2011-07-14 20:18:06

标签: php .htaccess http-status-code-404 clean-urls

我正在尝试使用php制作干净的网址并且我遇到了一些错误。希望有人可以提供帮助。

我的.htaccess如下:

# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
# this is the initialization
# For security reasons, Option followsymlinks cannot be overridden.
#Options         +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine   On
RewriteBase     /
# these are the rewrite conditions
RewriteCond     %{REQUEST_FILENAME}     !-f
RewriteCond     %{REQUEST_FILENAME}     !-d
# and finally, the rewrite rules
RewriteRule     ^([a-zA-Z0-9\-]+)/?$    /price/index.php?var1=$1 [L,QSA]
RewriteRule     ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$   /price/index.php?var1=$1&var2=$2 [L,QSA]
RewriteRule     ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$    /price/index.php?var1=$1&var2=$2&var3=$3 [L,QSA]

实际上我正在尝试在子文件夹price/中创建干净的网址。

当我输入:mydomain.com/price/param1时,它完美无缺,它实际上会重定向到我 mydomain.com/price/index.php?var1=param1

但是当我尝试使用更多变量时,我会遇到问题。当我尝试访问mydomain.com/price/param1/param2时,我没有被重定向,并且出现404错误。

有什么想法吗?提前谢谢。

1 个答案:

答案 0 :(得分:4)

尝试:

# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php

<IfModule mod_rewrite.c>
    # This is the initialization
    # For security reasons, Option followsymlinks cannot be overridden.
    #Options +FollowSymLinks
    Options +SymLinksIfOwnerMatch
    RewriteEngine On
    RewriteBase /

    # /price/var1/var2/var3
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^price/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ /price/index.php?var1=$1&var2=$2&var3=$3 [L,QSA]

    # /price/var1/var2
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^price/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ /price/index.php?var1=$1&var2=$2 [L,QSA]

    # /price/var1
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^price/([a-zA-Z0-9\-]+)/?$ /price/index.php?var1=$1 [L,QSA]
</IfModule>