Mod rewrite mod_将请求重写为pretty url

Mod rewrite mod_将请求重写为pretty url,mod-rewrite,Mod Rewrite,假设我有一个url的形式:myurl.com/index.php?m=1,我想把它映射到myurl.com/aboutus,这意味着,我希望浏览器在上面的栏中显示后一个url。 所以我首先要做的是捕获aboutus并将其映射到index.php?m=1 现在,如果我键入myurl.com/aboutus,将显示正确的页面,但我也希望以相反的方式显示它,因此即使我键入/index.php?m=1,我也希望浏览器显示/aboutus 我如何通过mod_rewrite实现这一点 感谢您的帮助 干杯,

假设我有一个url的形式:myurl.com/index.php?m=1,我想把它映射到myurl.com/aboutus,这意味着,我希望浏览器在上面的栏中显示后一个url。 所以我首先要做的是捕获aboutus并将其映射到index.php?m=1

现在,如果我键入myurl.com/aboutus,将显示正确的页面,但我也希望以相反的方式显示它,因此即使我键入/index.php?m=1,我也希望浏览器显示/aboutus

我如何通过mod_rewrite实现这一点

感谢您的帮助

干杯, b

更新1


你想把数字映射到像1->about,2->news


而且,您想要的行为听起来像是一个无限重定向循环。

是的,这正是我想要的。对我来说,它看起来也像一个无限循环,但我不想在url中显示任何参数,但我已经有了页面,在html中,链接是用参数编码的,就像普通的get url一样,所以我不能修改它们以使其美观:这是可行的,但我如何才能对其他数字也这样做呢?对不起,我的问题根本不是泛化的:如果有很多这样的数字,我建议从/index.php?m=。。。请求index.php本身中正确命名的页面。只需检查查询字符串。只有4个,我无法修改index.php:-/只有4个?如果我只是简单地复制上面除1行之外的行,并将m=1改为{2,3,4},将aboutus改为其他字符串,我会得到310:太多重定向。这个规则实际上是向后的。它给出500错误的原因是文件“aboutus”不存在。这是错误的,原因有几个。500错误实际上是因为第二条规则上的标志不正确,它应该是[R=301,L]。此外,由于用户指出规则位于.htaccess文件中,因此重写规则将与前导的/。此外,RewriteRule的第一组不能与querystring匹配,因此需要使用%{QUERY_STRING}的RewriteCond
RewriteRule ^aboutus$ /index.php?m=1
RewriteRule ^aboutus$ /index.php?m=1 [L]
RewriteRule ^index.php\?m=1$ /aboutus [301,L]
RewriteEngine on


RewriteCond %{QUERY_STRING} =m=1
RewriteCond %{REQUEST_URI} =/index.php
RewriteRule ^.* /aboutus? [R=301]


RewriteRule ^aboutus /index.php?m=1 [QSA]
RewriteEngine on

RewriteCond %{QUERY_STRING} =m=1
RewriteCond %{REQUEST_URI} =/index.php
RewriteRule ^.* /kepek? [R=301]

RewriteCond %{QUERY_STRING} =m=2
RewriteCond %{REQUEST_URI} =/index.php
RewriteRule ^.* /paroknak? [R=301]

RewriteCond %{QUERY_STRING} =m=3
RewriteCond %{REQUEST_URI} =/index.php
RewriteRule ^.* /magam? [R=301]

RewriteCond %{QUERY_STRING} =m=4
RewriteCond %{REQUEST_URI} =/index.php
RewriteRule ^.* /kapcsolat? [R=301]


RewriteRule ^kepek /index.php?m=1&redirected=1 [QSA]
RewriteRule ^paroknak /index.php?m=2&redirected=1 [QSA]
RewriteRule ^magam /index.php?m=3&redirected=1 [QSA]
RewriteRule ^kapcsolat /index.php?m=4&redirected=1 [QSA]