如何重定向网址?

时间:2019-01-09 21:28:46

标签: .htaccess url-rewriting silverstripe

我在Silverstripe网站上重定向URL时遇到问题。我有一个新闻提要页面,其中包含分页样式的文章摘要。最初显示20条文章,然后根据选择的页码切换到下20条文章。这只是标准的博客布局。当我单击第2页时,它应该导航到https:// ***** / news /?count = 20,第3页显示为https:// ***** / news /?count = 40等。但是,单击博客页码后,它会导航到https:// ***** / news / news /?count = 20。因此,导航链接不会重写父URL。

除此以外,我所有其他Silverstripe网站都可以在相同的博客布局下正常运行,而且我看不出有任何理由来调整默认代码。我想添加这样的.htaccess重定向

Redirect 301 /news/news/?start=20 https://******/news/?start=20

但是我没有运气能使它工作。请为我提出一个解决方案。

我期望的输出是重定向到正确的URL

https://******/news/?start=20

1 个答案:

答案 0 :(得分:1)

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. I assume the cause of that issue is that you hand out relative references (so something like news/...) instead of absolute references (/news/...). I strongly suggest that you handle the cause instead of trying to fix the symptom.