Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

.htaccess - Adding a word to the URL via htaccess

I've been struggling with a problem and have tried many other suggestions shown on this forum but have been unsuccessful.

I need to modify blog urls on my web site.

This is the current url:

https://www.example.com/my-blog/2021-outloook

I need the url to be this:

https://www.example.com/my-blog/entry/2021-outloook

So I'm trying to add the word "entry" to the url for the blog posts.

I've been trying to do this via htaccess without success.

Can anyone help?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  1. Look for this line in your .htaccess. If it doesn't exist, add it.

     RewriteEngine On
    
  2. Add this line below RewriteEngine On.

     RewriteRule ^my-blog/(.*)$ /my-blog/entry/$1 [R=301,L]
    

That will redirect your current URL as described. The R=301 makes this a permanent 301 redirect. The L directive tells Apache to stop applying any rules that follow.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...