如何重写这样的链接
http://stanime.pe.hu/content.php?idf=15&link=Katsugeki--Touken+Ranbu
到http://stanime.pe.hu/15/Katsugeki--Touken+Ranbu
即时编码和解码使用Urlencode和urldecode我的url
在数据库整理im使用latin1_swedish_ci
所以, space
将取代+
和/
replace%2f
和更多…
这是我的.htacces代码
RewriteEngine On # external redirect from actual URL to pretty one RewriteCond %{THE_REQUEST} \s/+content\.php\?link=([^\s&]+) [NC] RewriteRule ^ /%1? [R=302,L,NE] # internal forward from pretty URL to actual one RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ content.php?link=$1 [B,L,QSA]
首先,您需要在vhost或http.conf
文件中添加此指令:
AllowEncodedSlashes On
这将允许编码的斜线字符,即URL中的%2F
。
您可以在您的网站根目录.htaccess中使用这些规则:
RewriteEngine On # external redirect from actual URL to pretty one RewriteCond %{THE_REQUEST} \s/+content\.php\?idf=([^\s&]+)&link=([^\s&]+) [NC] RewriteRule ^ /%1/%2? [R=302,L,NE] # internal forward from pretty URL to actual one RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([\w-]+)/(.+)$ content.php?idf=$1&link=$2 [B,L,QSA]
你必须添加像下面的字符规则。 因为你的数据是字符形式的,不仅是你在这里定义的url数字。
RewriteRule ^content/([A-Za-z0-9-_]+)/?$ content.php?link=$1 [NC,L]