D
D
devhub162017-05-02 17:19:50
PHP
devhub16, 2017-05-02 17:19:50

How to make the right transition in htaccess?

Hello! There is a small problem - I'm making a link shortener like vk.cc.
There is a link.php file, which is located in the root of the site. You need to do this - when you just go to site.com/link, a page with a form for shortening the link opens, and when you go to site.com/link/sdsffdf, the page address is displayed.
In htaccess I wrote like this:
RewriteRule ^link/(.*)$ link.php?link=$1 [PT,L,QSA]
RewriteRule ^link/*$ link.php [L,QSA]
The problem is that when you go to site.com/link/sdsffdf, the site address changes to site.com/link/link/sdsffdf, that is, the link itself is duplicated. How to make it not change, but just site.com/link/sdsffdf?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2017-05-03
@devhub16

known problem, easy to
fix
a
Math part of my friend;)
now looking ahead, in the case when a redirect from a page with a GET parameter: - it is not part of the url does not see RewriteRule
For this, a two-level construction with RewriteCond is used
And if it were necessary to redirect in the opposite direction.

RewriteCond %{QUERY_STRING} (^|&)link\=\$1($|&)
RewriteRule ^link\.php$ /link/? [L,R=301]

Crap around the edges of the get parameter is and or if there is more than one get.
And finally, yummy
https://donatstudios.com/RewriteRule_Generator

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question