M
M
Mois2017-05-04 16:28:43
Apache HTTP Server
Mois, 2017-05-04 16:28:43

Redirect from old URLs to converted CNCs?

I decided to take care of more or less readable urls.
The idea is this:

Было:                      Стало:
ex.com/maker.php?id=mois   ex.com/maker/mois
ex.com/condition.php?id=1  ex.com/condition/1
ex.com/expample.php        ex.com/expample

Accordingly wrote in .htaccess
RewriteEngine on

RewriteRule ^maker/([a-z]+)/? maker.php?id=$1 [L]
RewriteRule ^maker/([a-z]+)? maker.php?id=$1 [L]

RewriteRule ^condition/([0-9]+)/? condition.php?id=$1 [L]
RewriteRule ^condition/([0-9]+)? condition.php?id=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)/$ $1.php

And everything works, but only now it is necessary that when clicking on old links there is a redirect to new ones, with the server response code 301 (for search engines).
Wrote this (not working):
RewriteCond %{QUERY_STRING} ^id=([a-z]+)$ [NC]
RewriteCond %{QUERY_STRING} !htaccess=Y
RewriteRule ^(.*) /maker/%1? [R=301,L]

But the campaign is a permanent redirect (from the old url to the new one, and vice versa) is now obtained.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2017-05-04
@shambler81

# 301 --- ex.com/maker.php?id=1 => ex.com/maker/1
RewriteCond %{QUERY_STRING} (^|&)id\=1($|&)
RewriteRule ^ex\.com/maker\.php$ http://ex.com/maker/1? [L,R=301]

# 301 --- ex.com/condition.php?id=1 => ex.com/condition/1
RewriteCond %{QUERY_STRING} (^|&)id\=1($|&)
RewriteRule ^ex\.com/condition\.php$ http://ex.com/condition/1? [L,R=301]

# 301 --- ex.com/expample.php => ex.com/expample
RewriteRule ^ex\.com/expample\.php$ http://ex.com/expample? [L,R=301]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question