apache - HTACCESS 上的自定义重写
问题描述
我的网站上已经有一个 htaccess 文件,它可以完成以下工作。例如,它将example.com/steve转换为example.com/profile.php?id=steve。
这意味着像example.com/something这样的 url应该去配置文件。
现在,我在从网站的其他 url 中删除 .php 扩展名时遇到了问题。
例如example.com/home应该打开主页,但它认为这是一个名为“home”的配置文件。
我们怎么能两者兼得?
我的 htaccess 文件
RewriteEngine on
RewriteCond %{REQUEST_METHOD} !^POST$
# Forcing HTTPS
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ profile.php?id=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ profile.php?id=$1&amount=$2 [L]
解决方案
推荐阅读
- android - 使用 phonegap/cordova 将自定义首选项添加到 android 设置
- python - 使用 python 绘制 3D 表面:raise ValueError("Argument Z must be 2-dimensional.") matplotlib
- php - 从php中的日期时间数组中过滤掉记录
- android - 长时间延迟后Android创建选择器显示
- node.js - 使用 TS 的路径映射调试 Nest App
- apache-spark - spark.executor.memory 未设置。显示默认值
- javascript - 未捕获的类型错误:无法读取未定义的属性“rightAnswer”
- java - Java EE Websocket编程端点如何使用Pathparams?
- spring - 关联字段不能用于更新项的路径表达式 Spring Data JPA
- java - Intellij IDEA Kotlin - 如何在同一列中发表评论?