htaccess breaks with (an escaped) dash in the redi

2019-10-22 03:45发布

我有一组网址是形式www.website.co.uk/businessname

这些是为了做一个htaccess的代理重定向到从服务器上的另一个域提取数据。

这是我有:

#Start Business pages
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^www.outputside.org.uk/swellcottage$
RewriteRule ^(.*) http://www.datasite.co.uk/$1 [P]

RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^www.outputsite.org.uk/hawthorn-books$
RewriteRule ^(.*) http://www.datasite.co.uk/$1 [P]
#End Business Pages

第一条规则的作品完美,显示的内容http://www.datasite.co.uk/swellcottage的URL www.outputsite.org.uk/swellcottage但第二条规则/条件不起作用。

我看着转义-字符的URL像这样:

  RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^www.outputsite.org.uk/hawthorn\-books$
    RewriteRule ^(.*) http://www.datasite.co.uk/$1 [P]
    #End Business Pages

但是,这似乎仍然没有正确地搞,重写规则不工作,该网站与该网页的后退404回复www.outputsite.org.uk/hawthorn-books不存在。

还有什么地方,我应该怎么回事逃脱破折号或其他什么地方错了我在这里的语法? 干杯

PS。 我有它那个文件名(的index.php)和文件夹名称(/地方/)不受代理重定向。

UPDATE

我在我的htaccess的详细规则:

#to add www. to each request. 
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301]

#Start biz pages
...
#End biz Pages

#to prevent error looping
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

我还与运行相同的代码上面hawthornbooks没有几许,躲过或以其他方式和代码工作正常,所以我需要找出逃避连字符的正确途径。 所有的代码和工作是UTF-8。

注:此问题会出现类似于如果我把一个为什么“ - ”破折号在我的htaccess的规则不起作用? 但我发现没有办法解决这个问题。

Answer 1:

如果问题仅仅是一个连字号这应该工作:

#Start Business pages
RewriteCond %{HTTP_HOST} ^(www\.)?outputside\.org\.uk$ [NC]
RewriteRule ^(swellcottage)/?$ http://www.datasite.co.uk/$1 [P,NC]

RewriteCond %{HTTP_HOST} ^(www\.)?outputside\.org\.uk$ [NC]
RewriteRule ^(hawthorn.books)/?$ http://www.datasite.co.uk/$1 [P,NC]
#End Business Pages


Answer 2:

这样做的目的是暂时的,而不是一个永久的解决方案,但你可以尝试以下规则:

RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^www.outputsite.org.uk/hawthorn([^\/]*)\/?$
RewriteRule ^(.*) http://www.datasite.co.uk/$1 [P]

这将寻找其符合图案的任何URI www.outputsite.org.uk/hawthorn后跟任意数量的其不是字符(或零个字符) / ,然后与(可选的)结束/



文章来源: htaccess breaks with (an escaped) dash in the redirect URL