Php 如何用htaccess重写url并用破折号替换下划线
我有一个运行在apache服务器上的WordPress站点,我想以SEO友好的方式重写一些URL,那么如何做到这一点呢 目前,我有这个网址Php 如何用htaccess重写url并用破折号替换下划线,php,wordpress,.htaccess,mod-rewrite,Php,Wordpress,.htaccess,Mod Rewrite,我有一个运行在apache服务器上的WordPress站点,我想以SEO友好的方式重写一些URL,那么如何做到这一点呢 目前,我有这个网址 www.example.com/about-us/?id=what_we_do_1 www.example.com/about-us/?id=why_us 我想要这样的 www.example.com/about-us/what-we-do-1 www.example.com/about-us/why-us 为了这个 www.example.com/
www.example.com/about-us/?id=what_we_do_1
www.example.com/about-us/?id=why_us
我想要这样的
www.example.com/about-us/what-we-do-1
www.example.com/about-us/why-us
为了这个
www.example.com/media/?id=team
www.example.com/media/?id=abc_xyz
我想要这样的东西
www.example.com/media/team
www.example.com/media/abc-xyz
我当前的.htaccess如下所示
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#开始WordPress
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
转换URL,如
/index.php?p=test
到
/index.php/test
RewriteEngine On
RewriteCond %{QUERY_STRING} p=(.+)
RewriteRule ^/?index.php$ /index.php/%1? [R,L]
你的情况就是这样
RewriteEngine On
RewriteCond %{QUERY_STRING} p=(.+)
RewriteRule ^/?about-us?$ /about-us/%1? [R,L]
类似地,对于其他页面您可以尝试将下划线转换为破折号:-
RewriteEngine On
RewriteBase /
之后,对于另一个url:-
1) www.example.com/about us/?id=我们做什么1
htaccess规则将是:-
RewriteRule ^about-us/(.*)$ about-us/?id=$1 [QSA,L]
它可能会对您有所帮助。您的网站是WordPress的吗谢谢Piyus,但它不起作用。当我这样做的时候,它会把我带到404。jQuery使用“?id=why_us”这样的id来显示您的第一条规则是什么?它现在对您有帮助吗?无论您在后面传递了什么关于我们的信息,它都将作为id传递到该页面。这对您不合适吗?