【发布时间】:2018-03-04 17:44:00
【问题描述】:
我想在 php 应用程序中使用 htaccess 将 URL 中的“+”更改为“-”
示例 http://hddir.com/videos/kodak+black 到 http://hddir.com/videos/kodak-black
我的 htaccess 代码
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php
RewriteRule ^index\.php$ / [L,R=301]
RewriteRule ^videos/(.+)/(.+)/(.+)/(.+) search.php?q=$1&order=$2&type=$3&ptk=$4
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /search(?:\.php)?\?q=([^\s&]+) [NC]
RewriteRule ^ videos/%1? [R=302,L]
# internal forward from pretty URL to actual one
RewriteRule ^videos/(.+)$ search.php?q=$1 [L,QSA,NC]
RewriteRule ^video/(.+).html$ watch.php?v=$1
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
#######Options -Indexes
ErrorDocument 404 /index.php
【问题讨论】: