【发布时间】:2015-04-24 16:13:20
【问题描述】:
我已经找了一段时间了,但我不能完全解决这个问题......所以来吧......我已经编辑了我的网址,以便当我有一个网址时:
http://example.co.uk/Review.php?type=anime&type2=tv&id=109&title=shingekinobahamutgenesis
变成:
http://example.co.uk/anime/tv/109/shingekinobahamutgenesis/
使用 .htaccess。这一点进展顺利,新 URL 可以正常工作,但是旧 URL 不会重定向到此 URL,并且也可以正常工作。当人们使用我们的移动网站链接时,这会导致问题,因为它会将他们重定向到未更改的旧 URL。
我们的 .htaccess 代码是这样的:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.co.uk [NC]
RewriteRule (.*) http://example.co.uk/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \ /(.*?)(%20)([^\?\ ]*)
RewriteRule ^ /%1%3 [L,R=301,NE]
RewriteRule ^adminarea/?$ /adminarea.php [L,QSA]
RewriteRule ^calendar/?$ /calendar.php [L,QSA]
RewriteRule ^contact/?$ /contact.php [L,QSA]
RewriteRule ^searching/?$ /searching.php [NC,L,QSA]
RewriteRule ^admin/([A-Za-z0-9-]+)/?$ /admin/$1.php [NC,L,QSA]
RewriteRule ^([A-Za-z0-9-]+)/?$ /search.php?type=$1 [NC,L,QSA]
RewriteRule ^view/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /search.php?type=$1&im=$2&name=$3 [NC,L,QSA]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /search.php?type=$1&genre=$2 [NC,L,QSA]
RewriteRule ^([A-Za-z0-9-]+)/list/([A-Za-z0-9-]+)/?$ /search.php?type=$1&letter=$2 [NC,L,QSA]
RewriteRule ^extra/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /rrww12o.php?type=$1&id=$2&genre1=$3&title=$4 [NC,L,QSA]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /Review.php?type=$1&type2=$2&id=$3&title=$4 [NC,QSA,L]
RewriteRule ^([A-Za-z0-9-]+)/?$ /$1.php [L,QSA]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
ErrorDocument 404 /error404.php
CheckSpelling on
RewriteBase /
# Check if mobile=1 is set and set cookie 'mobile' equal to 1
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]
# Check if mobile=0 is set and set cookie 'mobile' equal to 0
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]
# cookie can't be set and read in the same request so check
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [S=1]
# Check if this looks like a mobile device
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|iphone|ipod|iemobile|windows\ phone|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
RewriteCond %{HTTP:Profile} !^$
# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST} !^m\.
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP:Cookie} !\mobile=0(;|$)
# Now redirect to the mobile site
RewriteRule ^ http://m.example.co.uk%{REQUEST_URI} [R,L]
我尝试了多个版本的 [R=301] 和 [R] 重定向,但如果我只是将它添加到我有 [NC,QSA,L] 的末尾,它会将重写的链接重定向到原始链接(当然是错误的方式)。
需要 $1 的原因是这不是一个静态 URL,因为它涵盖了指向不同 MySQL 记录的多个链接,因为记录总是在增加,这必须像现在一样保持自动。
谁能帮忙?
【问题讨论】:
标签: string .htaccess variables mod-rewrite redirect