2013-05-18 107 views
0

如何重寫此URL?RewriteEngine隱藏擴展名和GET

http://website.com/file.php?lang=enhttp://website.com/file/en

文件名和參數可以改變,我發現很多話題就把我沒有發現兩個擴展的組合和GET參數

更新:我得到這個工作隱藏PHP擴展現在如何添加參數

# Turn mod_rewrite on 
RewriteEngine On 

# hide .php extension 
# To externally redirect /dir/file.php to /dir/file 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] 
RewriteRule^%1 [R=302,L] 

# To internally forward /dir/file to /dir/file.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ $1.php [L,QSA] 

回答

0

試試這個配置

RewriteEngine On 
RewriteRule ^file/([a-zA-Z0-9_-]+)$ file.php?lang=$1 
1

從代碼和註釋,我可以說這是我的一個答案:P

爲了獲得在這個地方新http://website.com/file.php?lang=en to http://website.com/file/en有你的.htaccess這樣的:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/$1.php -f 
RewriteRule ^([^/]+)/([^/]+)/?$ /$1.php?lang=$2 [L,QSA] 

# hide .php extension 
# To externally redirect /dir/file.php to /dir/file 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] 
RewriteRule^%1 [R=302,L] 

# To internally forward /dir/file to /dir/file.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/$1.php -f 
RewriteRule ^(.+?)/?$ $1.php [L]