简体   繁体   中英

Htaccess redirect to relative url

I have an angular application and I'm currently using htaccess to send hardlinks to their appropriate angular routes:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^(.*) /index.html [NC,L]

However, I have a single route that I want to redirect to a different page, before this is done. For example, redirect the request site.com/view/25 -> site.com/pages.

Is there any way to change the request's url before it goes further into these htaccess rules? I've tried doing a simple redirect:

redirect /view/ /views

But on a hard refresh that sends me to /pages/25, ie the second part of the url is appended on.

Put your rules in the beginning (before angular's rules)

RewriteEngine On

RewriteRule ^view/25$ /pages [R=301,L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [NC,L]

RewriteRule ^(.*)$ /index.html [NC,L]

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