简体   繁体   English

重写.htaccess中的页码

[英]Rewrite page number in .htaccess

I have a problem with rewriting URLs in my website. 我在重写网站中的URL时遇到问题。 I managed to remove all .php extensions from my URLs and addd 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. 我设法从网址中删除了所有.php扩展名,并将所有mydomain.com/img?id=X重写为mydomain.com/img/X,但是一段时间以来我一直在努力解决另一件事,我将不胜感激救命。 My website consists of many pages and the link to page number X is mydomain.com/?page=X (eg mydomain/?page=3), but I want to rewrite that URLs to mydomain.com/page/X 我的网站由许多页面组成,指向页面X的链接是mydomain.com/?page=X(例如,mydomain /?page = 3),但是我想将该URL重写为mydomain.com/page/X。

Here is my .htaccess: 这是我的.htaccess:

RewriteEngine on
RewriteBase /
<nothing 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  

该规则会将/?page = X重写为/ page / X

RewriteRule ^page/([0-9]+)/?$ /?page=$1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM