假设我有一些网址,如下所示:
其中 testX (...)可能相同或不同。
我如何能够重写这些内容以使URL更引人注目?
县,专业,地址1,地址2,地址3,地址4 只是示例。还有更多。
假设我有这个特定的链接:
photographers.co.uk/html/photographers-10.cfm?county=New 汉普郡和专业=婚礼&地址4 =南朴茨茅斯
或
photographers.co.uk/html/photographers-10.cfm?county=New York& special = Wedding& address4 =朴茨茅斯新城
我喜欢当它找到像
这样的单词时的规则南朴茨茅斯
或
朴茨茅斯新城
遵循我的规则并使其看起来像:
南 - 朴次茅斯
或
朴茨茅斯新城
我的.htaccess是这样的:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)(?:\+|%20|\s)+(.+?)\sHTTP [NC]
RewriteRule ^ /%1-%2 [L,NE,R=302]
RewriteRule ^([_&/A-Za-z0-9\s]+)-([&/A-Za-z0-9\s]+)-([&/A-Za-z0-9\s]+)-Photographers?$ html/photographers-10.cfm?county=$1&speciality=$2&address4=$3&rwtn [NC,L]
RewriteCond %{QUERY_STRING} !rwtn
RewriteCond %{QUERY_STRING} ^county=(.*)&speciality=(.*)&address4=(.*)
RewriteRule ^html/photographers-10\.cfm$ http://www.photographers.co.uk/%1-%2-%3-Photographers? [R=301,L]
RewriteRule ^([_&/A-Za-z0-9\s]+)-Photographers/?$ html/photographers-4.cfm?county=$1&rwtn [NC,L]
RewriteCond %{QUERY_STRING} !rwtn
RewriteCond %{QUERY_STRING} ^county=(.*)
RewriteRule ^html/photographers-4\.cfm$ http://www.photographers.co.uk/%1-Photographers? [R=301,L]
RewriteRule ^([_&/A-Za-z0-9]+)-([&/A-Za-z0-9]+)-Photographers?$ html/photographers-5.cfm?county=$1&speciality=$2&rwtn [NC,L]
RewriteCond %{QUERY_STRING} !rwtn
RewriteCond %{QUERY_STRING} ^county=(.*)&speciality=(.*)
RewriteRule ^html/photographers-5\.cfm$ http://www.photographers.co.uk/%1-%2-Photographers? [R=301,L]
RewriteRule ^Canary-Wharf-London-Photographer/?$ html/photographers-9.cfm?address4=Canary-Wharf&county=London&rwtn [NC,L]
RewriteRule ^City-of%2520London-London-Photographer/?$ html/photographers-9.cfm?address4=City-of%20London&county=London&rwtn [NC,L]
RewriteRule ^East-London-London-Photographer/?$ html/photographers-9.cfm?address4=East-London&county=London&rwtn [NC,L]
RewriteRule ^Kingston-upon%2520Thames-London-Photographer/?$ html/photographers-9.cfm?address4=Kingston-upon Thames&county=London&rwtn [NC,L]
RewriteRule ^NOTTING-HILL-London-Photographer/?$ html/photographers-9.cfm?address4=NOTTING-HILL&county=London&rwtn [NC,L]
RewriteRule ^South-Woodford-London-Photographer/?$ html/photographers-9.cfm?address4=South-Woodford&county=London&rwtn [NC,L]
RewriteRule ^Stamford-Brook-London-Photographer/?$ html/photographers-9.cfm?address4=Stamford-Brook&county=London&rwtn [NC,L]
RewriteRule ^([_&/A-Za-z0-9\s]+)-([&/A-Za-z0-9\s]+)-Photographer/?$ html/photographers-9.cfm?address4=$1&county=$2&rwtn [NC,L]
RewriteCond %{QUERY_STRING} !rwtn
RewriteCond %{QUERY_STRING} ^address4=(.*)&county=(.*)
RewriteRule ^html/photographers-9\.cfm$ http://www.photographers.co.uk/%1-%2-Photographer/? [R=301,L]
答案 0 :(得分:0)
您可以将此规则用作您的第一条规则,以用连字符替换所有空格。空格可以在查询字符串中和/或REQUEST_URI中。
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)(?:\+|%20|\s)+(.+?)\sHTTP [NC]
RewriteRule ^ /%1-%2 [L,NE,R=302]
这将重定向:
/html/photographers-10.cfm?county=New York&speciality=Wedding&address4=Portsmouth New City
为:
/html/photographers-10.cfm?county=New-York&speciality=Wedding&address4=Portsmouth-New-City
请注意,所有空格都已转换为最终URI中的连字符