php - 使用 htaccess 从 index.php 重定向到 another.php 文件
问题描述
我想创建漂亮的网址。但是,我遇到了.htaccess 的一些问题。例如,我有 url domain/some.php?f=query-string。我想更改域/查询字符串(预期的 url)。是否可以通过.htaccess 更改/重定向。或者可能来自 php 文件本身。
这是我制作的一些 htaccess 片段,但我得到它空白/错误页面
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteRule ^/([^/.]+)$ some.php?f=$1 [NC,L]
</IfModule>
感谢您的关注。
解决方案
RewriteRule ^/([^/.]+)$ some.php?f=$1 [NC,L]
在中,模式.htaccess
匹配的 URL 路径不以斜杠开头,所以上面的内容永远不会匹配,它什么也不做。这应该写成如下:RewriteRule
RewriteRule ^([^/.]+)$ some.php?f=$1 [L]
此处不需要该NC
标志,因为正则表达式已经“不区分大小写”。
推荐阅读
- python - 如何使用分类 sklearn boston 住房数据集使用 matplotlib 绘制线性图
- java - java.lang.IllegalArgumentException 与 AnnotationConfigApplicationContext
- django - 使用基于类的视图 (CBV) Django 2.1 Python 重定向页面
- reporting-services - SSRS:连接字段的不同值
- c++ - nullptr 没有打破零终止字符串的循环
- python - 使用 Python 在 Heroku 上入门时遇到问题
- php - 试图在 Laravel 脚本中获取非对象的属性“服务”
- wpf - 将复选框值与 xaml 上的文本块文本绑定
- python - 如何将数据框拆分为 x 和 y
- javascript - 如何在 for-in 循环中使用 If 语句?