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

发布于 2024-11-20 00:29:59 字数 1148 浏览 2 评论 0原文

我正在尝试使用 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 错误。

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

I'm trying to make clean urls with php and im getting some errors. Hope someone can help.

My .htaccess is as follows:

# 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]

Actually I'm trying to make clean urls in the subfolder price/.

When I enter: mydomain.com/price/param1 it works perfect and it actually redirects me to
mydomain.com/price/index.php?var1=param1

But when I try to go forward with more variables is when I get the problem. When I try to access mydomain.com/price/param1/param2 I'm not redirected and a 404 error appears.

Any idea? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尐籹人 2024-11-27 00:29:59

尝试:

# 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>

Try:

# 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文