1

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

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

当我进入时:mydomain.com/price/param1它运行完美,它实际上将我重定向到 mydomain.com/price/index.php?var1=param1

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

任何想法?提前致谢。

4

1 回答 1

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>
于 2011-07-14T20:31:52.123 回答