【问题标题】:.htaccess is can not access user's profile.htaccess 无法访问用户的个人资料
【发布时间】:2017-10-08 16:10:32
【问题描述】:

我只是编写了以下代码来使用 .htaccess 访问用户的个人资料,但它不起作用。

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?username=$1

【问题讨论】:

  • 它没有重定向,你得到一个错误,PHP 没有得到username 值,会发生什么?网址是什么? a-zA-Z0-9_ 可以是\w/ 可以通过? 设为可选。

标签: php regex .htaccess mod-rewrite


【解决方案1】:

取决于您的网络服务器版本,您可能必须以/ 开头。最后一个/ 也是可选的,所以我们最终得到这个,假设profile.php 在您的文档根文件夹中:

RewriteEngine On
RewriteBase /
RewriteRule ^/?([a-zA-Z0-9_-]+)/?$ profile.php?username=$1 [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多