Apache2 ModRewrite动态URL

时间:2014-07-13 19:46:36

标签: regex apache .htaccess mod-rewrite apache2

我正在尝试使用htaccess来重写我的url变量。

Example url http://example.com/assets/asset.php?id=9e233a25-994e-4262-8bfb-e477de1474ae

我需要的是

http://example.com/assets/9e233a25-994e-4262-8bfb-e477de1474ae

我的htaccess文件如下所示:

RewriteEngine On
RewriteBase /


RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /asset\.php\?id=(.*)\ HTTP
RewriteRule ^ /%1\? [R,L]

RewriteRule ^(.*)$ /asset.php?id=$1 [L]

我应该在htaccess文件中加入什么,因为这不起作用?

1 个答案:

答案 0 :(得分:0)

将此代码放在DocumentRoot/.htaccess

RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} \s/+assets/asset\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /assets/%1? [R,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^assets/([^/]+)/?$ assets/asset.php?id=$1 [L,QSA,NC]