S
S
skyfly20102016-09-10 19:37:35
htaccess
skyfly2010, 2016-09-10 19:37:35

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]

But it doesn't work.
My assumption is that the problem is caused by the presence of punctuation marks in the link text. or ? -_ : &
Similar situation with Cyrillic.
I searched the internet but didn't find an answer. Tell me how to be in such a situation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaliy Orlov, 2016-09-11
@skyfly2010

1) use urlencode to form url:

$baseUrl = 'mysite.ru/bla/id/';
$url = $baseUrl . urlencode('https://google.com/search/12');

2) simplify the regular expression, according to the requirements:
RewriteRule ^bla/id/(.+)$ index.php?id=$1 [NC,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question