Answer the question
In order to leave comments, you need to log in
How to write a rule for links in htaccess?
Good evening dear pro. I am writing a simple script to redirect links.
The point is, there are links on the site mysite.ru, you need to make sure that when you click on the link, a person gets to the page of the site, which in turn sends him to the link address.
For example:
mysite.ru/bla/id/ https://google.com/search/12
mysite.ru/bla/id/shop.ru?id=50 In
general, everything behind the id should fall into the variable. And then PHP already makes a redirect.
Now there is this code in ataccess:
RewriteRule ^bla/id/([\\/_A-Za-z0-9-]+)/?$ index.php?id=$1 [NC,L]
Answer the question
In order to leave comments, you need to log in
1) use urlencode to form url:
$baseUrl = 'mysite.ru/bla/id/';
$url = $baseUrl . urlencode('https://google.com/search/12');
RewriteRule ^bla/id/(.+)$ index.php?id=$1 [NC,L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question