在 XAMPP 中使用 .htaccess local 重写 URL

编程入门 行业动态 更新时间:2024-10-20 11:56:40
本文介绍了在 XAMPP 中使用 .htaccess local 重写 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的 .htacces 以

My .htacces begins with

RewriteEngine on RewriteBase /

(我在没有 RewriteBase 的情况下也尝试过...)

(I tried it also without RewriteBase...)

我尝试了以下所有重写规则来重写 URL

I tried all of the following rewriting rules to rewrite the URL

index.php?page=news

/博客

  • 重写规则^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/blog$index.php?page=$1 [L]
  • 重写规则 ^([^/]*)/blog$/sites/blog/index.php?page=$1 [L]
  • RewriteRule ([a-zA-z]+)/([a-zA-z]+)/blog$ index.php?page=$1 [L]

没有任何效果 - 没有错误.Mod_rewrite 已安装并正常工作.每次更改 .htaccess 中的某些内容时,我都会重新启动 Apache 和 MySQL.

Nothing works - no error. Mod_rewrite is installed and working. I restarted Apache and MySQL everytime I changed something in my .htaccess.

我还想更改如下所示的网址...index.php?page=single_news&category=release&id=9&headline=Beastie%20Boys%20III

I also want to change my URLs which looks like this... index.php?page=single_news&category=release&id=9&headline=Beastie%20Boys%20III

...进入:blog/release/9​​-Beastie-Boys-III

我迷路了.希望你能帮助我.

I am lost. Hope you can help me.

推荐答案

这是将链接从 www.domain.tld/index.php?page=blog 更改为 www.domain.tld/blog 是:

Here's the solution to change links from www.domain.tld/index.php?page=blog to www.domain.tld/blog is:

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^w+$ index.php?page=$0 [L] RewriteCond %{THE_REQUEST} index.php RewriteCond %{QUERY_STRING} ^page=(w+)$ RewriteRule ^index.php$ /%1? [R=301,L]

以及类似链接:www.domain.tld/index.php?page=single_news&id=1&headline=This%20Is%20A%Headline

解决办法是:

RewriteRule ^blog/(d+)-([w-]+)$ index.php?page=single_news&id=$1&headline=$2

使用此代码后,链接如下所示:www.domain.tld/blog/2-this-is-a-headline

After using this code, links looks like this: www.domain.tld/blog/2-this-is-a-headline

更多推荐

在 XAMPP 中使用 .htaccess local 重写 URL

本文发布于:2023-10-31 16:15:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546611.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   htaccess   XAMPP   URL   local

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!