URL Rewrite /index.php?page=sample to /sample.htm


URL Rewrite /index.php?page=sample to /sample.htm

对.htaccess很陌生,还不完全理解它的大部分内容。无论如何,目的是重写/index.php?page=sample-to-sample.htm。(或任何其他页面)

下面的脚本似乎部分起作用。如果我键入/sitmap.htm,它会显示该页面,但地址栏会更改为/index.php?page=站点地图。如何将url重写为更友好的url,以便在输入/sitmap.htm时和在输入/index.php时地址保持不变?page=sitemap它将重定向到/sitemap.htm,但仍然有效?

如果我听起来很困惑,我深表歉意。

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /test/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}'s/+getreal'.co'.uk/index'.php'?page=([^&'s]+) [NC]
RewriteRule ^ %1.htm? [L,R=301]
RewriteRule ^(.+?)'.htm?$ index.php?page=$1 [L,R=301]

您非常接近。但是THE_REQUEST不包含域名。

试试这个代码:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /test/
RewriteCond %{THE_REQUEST} /index'.php'?page=((?!login'b)[^&'s]+) [NC]
RewriteRule ^ %1.htm? [L,R=302]
RewriteRule ^(.+?)'.htm$ index.php?page=$1 [L,NC,QSA]