Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

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

apache - How can I rewrite URLs by removing a part of it with regex?

I have a series of URLs like this:

https://pocketnews.it/folder/subfolder/1234-rqoiryiewoqryiuewoqyroiwqhfkjlahflkdjsa

and I need to remove a part of it that which changes slightly between different URLs, like the following:

folder/subfolder/1234-
folder3/subfolder2/32456-
folder3/subfolder3/1234-

To obtain URLs like this one:

https://pocketnews.it/rqoiryiewoqryiuewoqyroiwqhfkjlahflkdjsa

I thought about using regex in the rewrite rules like this:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule ^pocketnews.it/(.*)[-]$ http://pocketnews.it/$1 [R=301,L]
</IfModule>

But it doesn't work

How can I achieve what I want?


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

1 Answer

0 votes
by (71.8m points)
RewriteRule ^(.*)[-](.*)$ https://pocketnews.it/$2 [R=301,L]

Some sites helps with regexp, like https://regexr.com/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...