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?

图片转代码服务由CSDN问答提供 功能建议

我需要301重定向 www.example.com/sample-page-1 www.example.com/en/sample-page-1 以及从文件 sample-page-1.php提供的http要求 此规则正常:

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

但是,我怎样才能有一组规则匹配 任何页面,如 sample-page-2 corporate-info customer-service 等?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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]
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题