I'm thinking of creating a blog-like script.
https://www.hoge.com/articles/0f60e2776530c9efa2e35c707d455a79
When you access the address, there
https://www.hoge.com/articles/?id=0f60e2776530c9efa2e35c707d455a79
I would like to see the contents of , but would it be possible to do this by redirecting by .htaccess?
.htaccess
It depends on whether you want to rewrite or redirect.
Rewrite
The browser of the person who accessed it simply by rewriting shows the original address.
Redirect
While rewriting, inform the user that the URL has changed and the browser displays the rewriting address.
Among them, the 301 redirect is something that I have accessed, but the original address has been changed to a rewritten address, so please use this address.
302 Redirects are like using a rewritten address for some reason.
Use mod_rewrite.
RewriteEngine on
Narrow by RewriteCond condition
RewriteRule RewritePre-rewrite flag (where R=301 is written and redirected)
Write as shown in .
In this case
RewriteRule^articles/(.+)$/articles/?id=$1[R=301,L]
I think it will be like this.
You do not need to specify a redirect for R=301, but if you insert a domain as a caution, it will be treated as an external redirect, and the browser will receive a 302 code (redirect), resulting in a redirect.
© 2024 OneMinuteCode. All rights reserved.