简体   繁体   中英

Combining 2 htaccess rules for redirecting html pages to their updated php versions

i have some rules in my htaccess file that convert php query strings into paths. It looks like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*?)/?$ index.php?s=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ index\.php\?s=([^\s]*)
RewriteRule ^/?(.*?)/?$ %1?%2%3 [L,R=301]

Now all the URLs such as mysite.com/index.php?s=whatever are converted into mysite.com/whatever so it works as expected. However, since my site used to be on html and there is still a lot of links out there that link to html pages that dont exist anymore, i want them to redirect to their new php counterparts. So if somebody click on a link thats says mysite.com/whatever.html it should take them to mysite.com/whatever automatically. I tried the code below:

RewriteEngine On
RewriteBase /
RewriteRule ^index\.html?$ / [NC,R,L]

but i dont know how to combine both. Any hint please?

Thank you.

尝试在您的.htaccess中添加以下代码:

RewriteRule ^([A-Za-z0-9]+).html$ http://mysite.com/$1 [R=301,L]

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