在 XAMPP 中使用 .htaccess local 重写 URL [英] Rewriting URL with .htaccess local in XAMPP

查看:27
本文介绍了在 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.

推荐答案

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

Here's the solution to change links from http://www.domain.tld/index.php?page=blog to http://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]

以及类似链接:http://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

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

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

这篇关于在 XAMPP 中使用 .htaccess local 重写 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆