简体   繁体   中英

Apache2 ModRewrite Dynamic Url

I am trying to use htaccess to rewrite my url variables.

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

what I need is

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

My htaccess file looks like this:

RewriteEngine On
RewriteBase /


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

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

What should I put into my htaccess file as this is not working?

Place this code in your 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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM