首页 > 解决方案 > 我想使用 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,而不是同时删除。

标签: .htaccessurlmod-rewriteurl-rewriting

解决方案


为什么它与重写有关?你可以做

 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?

编辑

我想你可以在这里试试


推荐阅读