.htaccess - 我想使用 url 重写来缩短我的 url,但它不起作用
问题描述
我试图缩短url
更多,但我也使用 url 重写从 url中删除.php
或文件扩展名。.html
我不能同时运行两者。
删除扩展并尝试缩短链接
site.com/profile.php?id={用户名}
至
site.com/用户名。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-z]+)$ profile.php?id=$1 [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^\..*?$ $1.html [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^\..*?$ $1.php [NC,L]
只是我尝试做的第一件事,或者删除扩展名(但不能同时删除,不能同时删除 .html 和 .php),或者删除 profile.php?id,而不是同时删除。
解决方案
为什么它与重写有关?你可以做
function processAjaxData(response, urlPath){
document.getElementById("content").innerHTML = response.html;
document.title = response.pageTitle;
window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath); }
喜欢它在这里:如何在不重新加载页面的情况下修改 URL?
编辑
我想你可以在这里试试
推荐阅读
- oracle-sqldeveloper - 比较 SQL Developer 中的存储过程 - 为匹配重音符号设置 NLS_CHARACTERSET
- python - 在python中创建流图,ValueError:'x'的行必须相等
- image - 如何在 React Native 中将图像 URI 转换为 Byte[](Byte array)
- scala - 使用具有默认值的 pureconfig 将配置解码为案例类
- python - 更改文本大小 Python
- mysql - 如何为只有一个地址作为参数的聊天应用组创建查询?
- azure - 运行 Set-AIPAuthentication 后 Azure 信息保护中没有 AIP 扫描程序节点
- html - 角度:
- 由 document.execCommand 添加的只能看到 styles.css 中的 css 规则,而不是组件的 css
- json - 使用 PowerShell 从 JSON 文件中获取某些值
- amazon-web-services - AWS EKS - 无法从 cli 读取任何容器的日志