2014-07-13 74 views
1

我想用htaccess來重寫我的url變量。Apache2 ModRewrite動態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的文件,因爲這是不工作?

回答

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] 
+0

確定它可以在根文件夾但對於子文件夾? –

+0

不客氣。爲此,您需要爲描述需求清楚地創建一個新問題。 – anubhava