【问题标题】:How to make exeptions in .htaccess如何在 .htaccess 中产生异常
【发布时间】:2020-06-25 10:19:30
【问题描述】:

我正在制作一个社交网站
目前看起来像这样

                              htdocs(xampp)
                                    |
 ___________________________________|___________________________________
 |                                                                      |
login(folder)                                                        index.html

如果有人访问 http://localhost/index.html?u=Francis 并且用户 Francis 存在,它将向他们显示 Francis 个人资料,但如果用户 Francis 不存在,则将他们重定向到登录(文件夹)
然后我使用 .htaccess 来代替输入 http://localhost/index.html?u=Francis 你可以输入 http://localhost/francis 它会显示你弗朗西斯的个人资料,但我无法访问 http: //localhost/login 因为没有用户喜欢登录所以它一直重定向

如何让所有看起来像 http://localhost/francis 除了 http://localhost/login 的网址都显示他们的个人资料,

我的.htaccess 文件:

RewriteEngine on

RewriteRule ^([a-zA-Z0-9_-]+)$ index.html?u=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.html?u=$1

【问题讨论】:

  • 欢迎来到 StackOverflow!您能否向我们提供您的 .htaccess 代码?
  • @Vepthy 我的代码是
  • @Vepthy RewriteEngine on RewriteRule ^([a-zA-Z0-9_-]+)$ index.html?u=$1 RewriteRule ^([a-zA-Z0-9_-]+) /$ index.html?u=$1

标签: javascript php .htaccess


【解决方案1】:

您需要编写php代码来检查用户Francis是否存在, 你不能用 htaccess 做到这一点,

您也可以使用 php 重定向到您的登录页面或文件夹:

header('Location: ...');

Documentation about header()

为了显示用户页面,我建议为此创建一条新路线,例如localhost/user/francis

RewriteRule user/(0-9a-zA-Z_-) index.php?u=$

【讨论】:

  • @user13782016 不客气,如果您满意,请接受我的回答:)。
猜你喜欢
  • 2015-02-15
  • 2020-06-15
  • 2012-09-21
  • 2020-01-31
  • 2019-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-10
相关资源
最近更新 更多