0

如何重写此 URL?

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]
4

2 回答 2

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]
于 2013-06-16T14:49:08.550 回答
0

试试这个配置

RewriteEngine On
RewriteRule ^file/([a-zA-Z0-9_-]+)$ file.php?lang=$1
于 2013-06-16T14:11:29.980 回答