【问题标题】:.htaccess pretty url with and without parameter and slash.htaccess 带有和不带参数和斜杠的漂亮 url
【发布时间】:2023-04-04 14:42:01
【问题描述】:

我的 .htaccess 文件中有以下代码。当我打开 https://example.com/tran 时,它显示 404 页面,但在 url 中添加斜杠,如 https://example.com/tran/ 有效。 我怎样才能让https://example.com/tran 重定向到https://example.com/tran/https://example.com/tran/parameter1 都可以工作,因为还想在url 中使用$_GET 方法从url 获取参数。

Options All -Indexes
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
<FilesMatch ".(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
 Order Allow,Deny
 Deny from all
</FilesMatch>

RewriteRule tran/(.*) transaction.php?id=$1

RewriteRule tran/(.*)/ transaction.php?id=$1

RewriteRule addr/(.*) address.php?id=$1   

RewriteRule addr/(.*)/ address.php?id=$1

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    你可以使用:

    RewriteRule tran(?:/(.*?)/?)?$ transaction.php?id=$1
    RewriteRule addr(?:/(.*?)/?)?$ address.php?id=$1
    

    而不是你的 4 条规则

    【讨论】:

      猜你喜欢
      • 2012-05-07
      • 2014-09-24
      • 1970-01-01
      • 2018-04-06
      • 2012-08-08
      • 2019-07-18
      • 2012-04-22
      • 1970-01-01
      • 2011-09-19
      相关资源
      最近更新 更多