带星号的 url 的 htaccess rewritecond
一些......好人......已经设置了一个指向我们网站的传入链接,如下所示: http://www.site.com/*our*-*services*/
我想重定向它,以便它指向: http://www.site.com/our-services/
我们的网站是一个 Wordpress 网站,因此我们的根 htaccess 文件中已经有一些重写内容。一个简单地从 URL 中删除星号的规则就可以了,但我不知道如何做到这一点,所以我尝试了以下方法 - 松散地基于复制现有的 Wordpress 规则 - 这是行不通的:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} (/\*our\*-\*services\*/)
RewriteRule . /our-services/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
它看起来像这个规则被忽略 - 错误的 URL 当前会将您重定向到我们的默认 Wordpress 404 页面。显然,我失败了:我应该把什么作为重写条件?
Some... fine person... has set up an incoming link to our site that looks like:http://www.site.com/*our*-*services*/
I'd like to redirect it so it points it to:http://www.site.com/our-services/
Ours is a Wordpress site so there's some rewrite stuff in our root htaccess file already. A rule that simply removes asterisks from the URL would do, but I can't figure out how to do that, so I tried the following - loosely based on copying the existing Wordpress rules - which isn't working:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} (/\*our\*-\*services\*/)
RewriteRule . /our-services/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
It looks like this rule is being ignored - the errant URL currently redirects you to our default Wordpress 404 page. Clearly, I am fail: what should I have put as the rewrite condition?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将删除您的第一个
RewriteCond
,然后仅使用此规则:RewriteRule \*our\*-\*services\*\/ /our-services/ [L]
I'd remove your first
RewriteCond
and then just use this rule:RewriteRule \*our\*-\*services\*\/ /our-services/ [L]
让他们更改传入链接。
星号在网址中保留,因此在这种情况下不应使用:
W3 Url 推荐
允许在网址中使用星号
Well get them to change there incoming link.
Asterisks are reserved in urls, so in this case it shouldn't be used:
W3 Url Recommendation
Allowing asterisk in URL