[英]How to redirect a URL?
I have a problem in redirecting a URL on a Silverstripe website. 我在Silverstripe网站上重定向URL时遇到问题。 I have a news feed page with a summary of articles in a paginated style.
我有一个新闻提要页面,其中包含分页样式的文章摘要。 It displays 20 articles initially and switches to the next 20 based on the page number chosen.
最初显示20条文章,然后根据选择的页码切换到下20条文章。 It is just the standard blog layout.
这只是标准的博客布局。 When I click on page 2 then it should navigate to https://*****/news/?count=20 and for page 3 as https://*****/news/?count=40 etc. However upon clicking the blog page number it navigates to https://*****/news/news/?count=20.
当我单击第2页时,它应该导航到https:// ***** / news /?count = 20,第3页显示为https:// ***** / news /?count = 40等。但是,单击博客页码后,它会导航到https:// ***** / news / news /?count = 20。 So the navigation link is not rewriting the parent URL.
因此,导航链接不会重写父URL。
All of my other Silverstripe websites work fine with the same blog layout except this and I don't see any reason to tweak the default code. 除此以外,我所有其他Silverstripe网站都可以在相同的博客布局下正常运行,而且我看不出有任何理由来调整默认代码。 I thought of adding a .htaccess redirect like this
我想到添加这样的.htaccess重定向
Redirect 301 /news/news/?start=20 https://******/news/?start=20
but I didn't have any luck to make it work. 但是我没有运气能使它工作。 Kindly suggest me a solution for this.
请给我一个解决方案。
The output I expect is to redirect to the right URL 我期望的输出是重定向到正确的URL
https://******/news/?start=20
Here is a simple redirection rule that should fix the symptom you describe: 这是一个简单的重定向规则,应该可以解决您描述的症状:
RewriteEngine on
RewriteRule ^/?news/news/(.*)$ /news/$1 [R=301,L]
But I doubt that approach is a good idea. 但是我怀疑这种方法是个好主意。 Simply because it tries to fix a symptom, not the cause.
仅仅是因为它试图解决症状,而不是原因。 The cause is that you actually create requests to URLs that contain the
/news/news/
issue which should never happen. 原因是您实际上创建了对包含
/news/news/
问题的URL的请求,该请求永远不会发生。 I assume the cause of that issue is that you hand out relative references (so something like news/...
) instead of absolute references ( /news/...
). 我认为导致该问题的原因是您分发了相对引用(例如
news/...
)而不是绝对引用( /news/...
)。 I strongly suggest that you handle the cause instead of trying to fix the symptom. 我强烈建议您处理原因,而不要尝试解决症状。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.