如何在PHP中更改URL格式

时间:2016-02-29 07:55:06

标签: php .htaccess

我想更改网址

http://localhost/Self-Content/img.php?v=YQHsXMglC9A&fmt=hqdefault.jpg

http://localhost/Self-Content/bUTdUaVmj8o/mqdefault.jpg

我试试这个.htaccess

RewriteEngine On
RewriteCond %{THE_REQUEST} /img\.php\?v=([^\s]+) [NC]
RewriteCond %{THE_REQUEST} /img\.php\&fmt=([^\s]+) [NC] 
RewriteRule ^ /%1? [NC,R,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ img.php?v=$1 [QSA,L,NC]
RewriteRule ^([^/]+)/?$ img.php?v=&fmt=$1 [QSA,L,NC]

我正在使用Wamp但是当我尝试此代码时,我收到此错误 Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

1 个答案:

答案 0 :(得分:0)

Self-Content/.htaccess内有这样的内容:

RewriteEngine On
RewriteBase /Self-Content/

RewriteCond %{THE_REQUEST} /img\.php\?v=([^&\s]+)&fmt=([^&\s]+)\s [NC] 
RewriteRule ^ %1/%2? [NC,R,L]

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