【问题标题】:I want to shorten my url using url rewriting, but it doesn't work我想使用 url 重写来缩短我的 url,但它不起作用
【发布时间】:2019-12-22 23:11:50
【问题描述】:

我试图进一步缩短 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,不能同时删除。

【问题讨论】:

  • 你在任何框架下工作吗?????
  • @MohitKumar 不,现在只有 php 和 html。
  • @DonPaul 帮自己一个忙,开始使用框架,它会为您完成这一切。
  • @GrumpyCrouton 我现在不能,我想解决这个问题。
  • @DonPaul 那解决这个问题

标签: .htaccess url mod-rewrite url-rewriting


【解决方案1】:

为什么与 Rewrite 有关系?你可以这样做

 function processAjaxData(response, urlPath){
 document.getElementById("content").innerHTML = response.html;
 document.title = response.pageTitle;
 window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath); }

喜欢这里:How do I modify the URL without reloading the page?

编辑

我想你可以试试这个HERE

【讨论】:

  • 是的,但我希望可以从任何地方访问该链接,而不仅仅是我的网站。
  • Something.com/?userID=2&profile....... 普通网址,你想这样做Something.com/id2 吗? (只是示例)没有像 codeigniter、laravel 或其他我不知道是否可能的框架。我的意思是它可能,但你将有很多工作要做。或者您要么更改为框架,要么最好更改页面上的 url 而无需重新加载它
  • 是的,我想转换 site.com/username 并将 .php 扩展名(如 site.com/login.php)删除为 site.com/login 。
  • 不,我想这不是我需要的。
  • 你可以用我刚刚给你的链接做site.com/login.php to site.com/login
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-15
  • 1970-01-01
相关资源
最近更新 更多