2015-07-21 58 views
1

我需要301重定向到www.example.com/sample-page-1www.example.com/en/sample-page-1的HTTP要求從文件送達sample-page-1.php用在.htaccess中沒有文件夾

此規則匹配的網址工作正常:

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-2corporate-info,customer-service等?

+2

的可能重複的[htaccess的:重寫規則模式匹配(http://stackoverflow.com/questions/19625484/htaccess-rewriterule-pattern-matching) – byako

回答

1

可以有規則的:

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^/.]+)/?$ /en/$1 [NC,L,R=301] 

RewriteRule ^en/([^/.]+)$ $1.php [L,NC] 
+1

謝謝@anubhava!它工作完美! – pbertuzzi

相關問題