简体   繁体   English

在index.php中重写

[英]Rewrite in index.php

I have a problem with rewriting hrefs in my website. 我在网站上重写href时遇到问题。 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. 首先,我设法从网址中删除了所有.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 /
<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

Right below this rule: 在此规则之下:

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

try adding: 尝试添加:

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

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

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

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