我的 .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
发布评论