dscrn1974 2015-07-21 14:15
浏览 40
已采纳

在.htaccess中匹配没有文件夹的网址

I need to 301 redirect www.example.com/sample-page-1 to www.example.com/en/sample-page-1 and the http requirement served from file sample-page-1.php

This rules works ok:

RewriteRule ^sample-page-1$ https://www.example.com/en/sample-page-1 [NC,R=301]
RewriteRule ^en/sample-page-1$ sample-page-1.php

However, how can I have one set of rules to match any page such as sample-page-2 , corporate-info , customer-service , etc?

  • 写回答

1条回答 默认 最新

  • douxing8323 2015-07-21 14:24
    关注

    You can have rules as this:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/.]+)/?$ /en/$1 [NC,L,R=301]
    
    RewriteRule ^en/([^/.]+)$ $1.php [L,NC]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?