简体   繁体   中英

How to redirect a URL?

I have a problem in redirecting a URL on a Silverstripe website. 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. 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. So the navigation link is not rewriting the parent 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. I thought of adding a .htaccess redirect like this

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

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM