String .htaccess重定向中的变量
我已经找了一段时间了,但我不能很好地解决这个问题…接下来…我编辑了我的URL,这样当我有一个URL时,例如: 它变成: 使用.htaccess。这一点进展顺利,新的URL可以正常工作,但是旧的URL不能重定向到此URL,也可以正常工作。当人们使用我们的移动站点链接将他们重定向到旧的未更改的URL时,这会导致问题 我们的.htaccess代码如下所示:String .htaccess重定向中的变量,string,.htaccess,variables,mod-rewrite,redirect,String,.htaccess,Variables,Mod Rewrite,Redirect,我已经找了一段时间了,但我不能很好地解决这个问题…接下来…我编辑了我的URL,这样当我有一个URL时,例如: 它变成: 使用.htaccess。这一点进展顺利,新的URL可以正常工作,但是旧的URL不能重定向到此URL,也可以正常工作。当人们使用我们的移动站点链接将他们重定向到旧的未更改的URL时,这会导致问题 我们的.htaccess代码如下所示: RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.example\.co.uk [NC]
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记录的多个链接,因为记录总是在增加,所以必须像现在一样保持自动
有人能帮忙吗?更新:不适用于OP
尝试一下:
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]
# Rerwite to Review.php
RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/([a-z0-9-]+)/([a-z0-9-]+)/?$ /Review.php?type=$1&type2=$2&id=$3&title=$4 [NC,QSA,END]
# Redirect old url to new url
RewriteCond %{QUERY_STRING} ^type=([a-z0-9-]+)&type2=([a-z0-9-]+)&id=([a-z0-9-]+)&title=([a-z0-9-]+)$ [NC]
RewriteRule ^Review\.php$ /%1/%2/%3/%4 [QSD,R,L]
注意Review.php
规则上的END
标志-这可以防止无限循环
因此,如果您请求
Review.php?type=anime&type2=tv&id=109&title=shingekinobahamutgenesis
,您将被重定向到anime/tv/109/shingekinobahamutgenesis
,然后将被重写。当我这样做时,似乎会杀死该站点…获得500个内部服务器错误可能是其他字符串查询…我将编辑代码以显示所有字符串查询。您的代码无论如何都会抛出一个内部服务器错误-没有我的新条件和规则…删除该错误对我不起作用。这是原始的站点链接:(原始的htaccess肯定有效)。我将QSD
放在URL上,这样原始的查询字符串就不会附加到URL上。