【问题标题】:.htaccess RewriteRule for category/subcategory/.../ in PHP.htaccess RewriteRule for category/subcategory/.../ 在 PHP
【发布时间】:2020-03-23 11:30:33
【问题描述】:

我在.htaccess 上提交了此代码

RewriteRule ^([0-9A-ZA-Z-]+)$ details.php?pro_id=$1 [QSA,NC,L]

当我访问localhost/index.php 并打开任何产品显示示例localhost/product-1 时,该产品就会显示。但是当我在localhost/country/city/place/product-1 中添加产品时,我找不到页面。如何重写 .htaccess 代码。在details.php 页面上为显示的产品信息编写代码。

所以我有这个:

localhost/index.php - localhost/product-url

我需要这个:

localhost/index.php - localhost/country/city/place/product-1`.

注意:在某些情况下,我将有 2 个类别,在某些情况下为 3。

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    你的.htaccess 应该是这样的

    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f  
    RewriteCond %{REQUEST_FILENAME} !-d  
    RewriteRule ^/([a-zA-Z0-9|]+)/([^/]*)/(.*)$ details.php [B,QSA]
    

    这将支持所有网址

    【讨论】:

    • 现在不打开新旧产品页面.htaccess
    • 当我将.htaccess 更改为此RewriteEngine On RewriteRule ^([0-9A-ZA-Z-]+)/([0-9A-ZA-Z-]+)/([0-9A-ZA-Z-]+)/([0-9A-ZA-Z-]+)$ details.php?pro_id=$1 [QSA,NC,L] 时,当我尝试访问localhost/country/city/place/product-1 时,我将自动重定向到localhost/index.php
    • details.php的内容是什么?
    猜你喜欢
    • 2020-02-05
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    • 2016-04-06
    • 1970-01-01
    • 2016-06-11
    • 2013-05-16
    • 2014-10-30
    相关资源
    最近更新 更多