Rewrite in index.php

好久不见. 提交于 2020-01-25 03:00:39

问题


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

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

回答1:


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]


来源:https://stackoverflow.com/questions/34503009/rewrite-in-index-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!