在 index.php 中重写

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

我在重写网站中的 href 时遇到问题.首先,我设法从 na URL 中删除了所有 .php 扩展名,然后我添加了将所有 mydomain/img?id=X 重写为 mydomain/img/X,但我一直在为另一件事而苦苦挣扎一段时间我将不胜感激任何帮助.我的网站由许多页面组成,页码 X 的链接是 mydomain/?page=X(例如 mydomain/?page=3),但我想将该 URL 重写为 mydomain/page/X

I have a problem with rewriting hrefs in my website. First of all I managed to remove all .php extensions from na URLs, then I added rewriting all mydomain/img?id=X to mydomain/img/X, but I have been struggling with one more thing for some time and I would appreciate any help. My website consists of many pages and the link to page number X is mydomain/?page=X (e.g mydomain/?page=3), but I want to rewrite that URLs to mydomain/page/X

这是我的 .htaccess:

Here is my .htaccess:

RewriteEngine on RewriteBase / <something not important> RewriteCond %{HTTP_HOST}//s%{HTTPS} ^www\.(.*)//((s)on|s.*)$ [NC] RewriteRule ^ http%3://%1%{REQUEST_URI} [L,R=301] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^img/([0-9]+)/?$ img.php?id=$1 RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php

推荐答案

就在这条规则的下方:

RewriteCond %{HTTP_HOST}//s%{HTTPS} ^www\.(.*)//((s)on|s.*)$ [NC] RewriteRule ^ http%3://%1%{REQUEST_URI} [L,R=301]

尝试添加:

RewriteCond %{THE_REQUEST} \ /+\?page=([0-9]+) RewriteRule ^ /page/%1? [L,R] RewriteRule ^page/([0-9]+)/?$ /?page=$1 [L]

更多推荐

在 index.php 中重写

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

发布评论

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

>www.elefans.com

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