在 index.php 中重写 [英] Rewrite in index.php
问题描述
我在重写网站中的 href 时遇到问题.首先,我设法从 na URL 中删除了所有 .php 扩展名,然后我添加了将所有 mydomain.com/img?id=X 重写为 mydomain.com/img/X,但我一直在为另一件事而苦苦挣扎一段时间我将不胜感激任何帮助.我的网站由许多页面组成,页码 X 的链接是 mydomain.com/?page=X(例如 mydomain/?page=3),但我想将该 URL 重写为 mydomain.com/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.com/img?id=X to mydomain.com/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.com/?page=X (e.g mydomain/?page=3), but I want to rewrite that URLs to mydomain.com/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 中重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!