在index.php中重写


Rewrite in index.php

我在网站中重写hrefs时遇到问题。首先,我设法从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

这是我的.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]