Home>

How to write 301 redirect .htaccess for a single page

https://www.example.com/sp/
When the above is accessed

https://www.example.com
How can I get it to be redirected to 301? (Only for a single page, not for each underlying directory)?

Since it was displayed by the user agent, the smartphone page with a different URL was displayed. However, because it is responsive, I want to redirect the top page as shown above.

However, since the number of pages is huge and it is difficult to make all pages responsive, and we want to make responsive support only for the pages that will be created in the future, we want to do a single page redirect for the top page only.

  • Answer # 1

    RewriteEngine On
    RewriteCond% {REQUEST_URI} ^ (/ sp/index \ .html |/sp/index |/sp /?) $
    RewriteRule ^. * $Https://example.com/ [R = 301, L]