【问题标题】:.htaccess PHP Parameter Friendly URL.htaccess PHP 参数友好 URL
【发布时间】:2022-11-29 01:54:05
【问题描述】:

我想让我的商店 URL 的 URL 友好。

当前 URL 结构

https://my-domain.com/store/store.php?page=packages&id=1

所需的 URL 结构

https://my-domain.com/store/packages/1

也可以直接访问 PHP 文件,例如:

https://my-domain.com/store/profile.phphttps://my-domain.com/store/profile

我需要怎么做?我真的很感激你能提供的任何帮助。

还可能值得注意的是,在基本目录中,WordPress 站点正在运行它自己的 .htaccess 文件。

我已经用这个试过了

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^store/store/page/(.*)/id/(.*) /store/store.php?page=$1&id=$2
RewriteRule ^store/store/page/(.*)/id/(.*)/ /store/store.php?page=$1&id=$2

但这没有用

【问题讨论】:

    标签: php .htaccess url-rewriting


    【解决方案1】:

    您可以在第一部分使用它:

    RewriteRule ^store/((?!store)[^/]+)/([^/]+)$ /store/store.php?page=$1&id=$2 [L]

    【讨论】:

      【解决方案2】:

      此代码将起作用。

      RewriteEngine 将从所有 PHP 文件中删除 .php RewriteRule 将像 page/id 一样重写 url

      用于删除 .php 扩展名

      RewriteEngine On
      RewriteCond %{THE_REQUEST} /([^.]+).php [NC]
      RewriteRule ^ /%1 [NC,L,R]
      RewriteCond %{REQUEST_FILENAME}.php -f
      RewriteRule ^ %{REQUEST_URI}.php [NC,L]
      
      

      对于页面/id

      
      <IfModule mod_rewrite.c>
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)? store.php?page=$1&id=$2 [L] 
      </IfModule>
      
      

      【讨论】:

        猜你喜欢
        • 2011-07-11
        • 2014-10-04
        • 2011-05-09
        • 1970-01-01
        • 2017-04-12
        • 2012-08-21
        • 2015-12-16
        • 2013-08-31
        • 2012-06-03
        相关资源
        最近更新 更多