简体   繁体   中英

How do I redirect https://www.hhl.com/articlename.html?a=b to https://www.hhl.com/articlename/?a=b

I just converted a website over to a new implementation. The old site had URLs that ended in .html; now I'm using the "normal" WordPress way in which they look like a directory. How do I redirect:

      https://www.hhl.com/articlename.html?a=b 
...to https://www.hhl.com/articlename/?a=b

Your question is a bit vague, but I assume that roughly is what you are looking for:

RewriteEngine on
RewriteRule ^/?articlename\.html$ /articlename/ [R=301,QSA]

And a general remark: you should always prefer to place such rules in the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those dynamic configuration files add complexity, are often a cause of unexpected behavior, hard to debug and they really slow down the http server. They are only provided as a last option for situations where you do not have access to the real http servers host configuration (read: really cheap service providers) or for applications insisting on writing their own rules (which is an obvious security nightmare).


UPDATE: In the comments you explained that the "articlename" portion of the URL is dynamic, that was not mentioned in the original question. Here is an updated version taking that into account:

RewriteEngine on
RewriteCond %{REQUEST_URL} !-f
RewriteRule ^/?([a-z0-9_-])\.html$ /$1/ [R=301,NC,QSA]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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