Answer the question
In order to leave comments, you need to log in
How to do the right 301 redirect?
Hi all! Guys tell me how to make a 301 redirect of this kind in htassecc? CNC works as it should, but the redirect does not want to work in any way.
Old address https://test.ru/parts/part.php?id=18427
New address https://test.ru/parts/18427
I'm doing this and it doesn't work!
RewriteEngine On
RewriteRule ^parts/([^/]*)$ /parts/part.php?id=$1 [L]
RewriteCond %{THE_REQUEST} " /parts/part\.php\?id=([^&]+)"
RewriteRule ^ https://test.ru/%1/%2/? [R=301,L,NE]
Answer the question
In order to leave comments, you need to log in
1) you need to remove the space after the first quote in the regular expression "/parts/part\.php\?id=([^&]+)"
2) you have only one "pocket" i.e. in %2 will be empty
3) in your id=([^&]+) the transfer protocol will be captured, there will be something like "123 HTTP/1.1", i.e. you need to add a space inside,
I recommend you do like this
RewriteCond %{THE_REQUEST} "/parts/part\.php\?id=([^& ]+)"
RewriteRule . test.php?test=%1
<?php
print_r($_REQUEST);
RewriteCond %{THE_REQUEST} "^(.+)$"
RewriteRule . test.php?test=%1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question