【问题标题】:htaccess rewrite in subdirectoryhtaccess 在子目录中重写
【发布时间】:2017-04-05 00:00:49
【问题描述】:

这可能是一个非常菜鸟的问题,但我对网络开发相对较新,并且在谷歌上搜索了很多,但找不到像我这样的东西。我有一个简单的 htaccess。

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^stores/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ stores/profile.php?sid=$1

这就像我想要的那样工作得很好

例如stores/profile.php?sid=12被改写成

stores/12/store-seo-name

在 stores 子目录中,我有一个页面显示每个商店列出的产品的详细信息,该页面采用两个参数(store_id 和 product_id) 我想这样改写

item_view.php?sid=12&p_id=35 到

item/12/35/product-seo-name

我尝试了很多方法,但我无法让它工作,当我在 stores 子目录中添加 htaccess 文件时,它给了我 404 错误。 任何帮助将不胜感激。

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    尝试使用此规则:

    RewriteEngine On
    RewriteRule ^item/([^/]*)/([^/]*)/product-seo-name$ /item_view.php?sid=$1&p_id=$2 [L]
    

    确保在测试之前清除缓存。

    【讨论】:

    • 谢谢@thickguru。当我编写完整路径时它起作用了 root/stores/item_view.php?sid=$1&p_id=$2
    猜你喜欢
    • 2019-05-28
    • 1970-01-01
    • 2012-05-06
    • 1970-01-01
    • 2014-01-27
    • 1970-01-01
    • 2010-10-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多