0

Нужно перенаправить юзера со старой версии страницы /show?id=708 на новую /show/708 вместо 708 любое число. Делал так:

RewriteCond %{REQUEST_URI} ^\/show
RewriteCond %{QUERY_STRING} ^id=(.*?)$
RewriteRule .* /show/$1 [L,R=301]
// циклическая переадресация


RewriteRule ^show?id=(.*?)$ /show/$1 [R=301,L]
//не работает

Сам .htaccess:

<files .htaccess>
order allow,deny
deny from all
</files>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]
Options All -Indexes
ServerSignature Off
<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
</ifModule>
<IfModule mod_gzip.c>
mod_gzip_on         Yes
mod_gzip_dechunk    Yes
mod_gzip_item_include file      \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include mime      ^text\.*
mod_gzip_item_include mime      ^application/x-javascript.*
mod_gzip_item_exclude mime      ^image\.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
<ifModule mod_headers.c>
<FilesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=43200"
</FilesMatch>
<FilesMatch "\.(js|css|txt)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
<FilesMatch "\.(flv|swf|ico|gif|jpg|jpeg|png)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
<FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
Header unset Cache-Control
</FilesMatch>
</IfModule>
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 5 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 604800 seconds"
ExpiresByType application/javascript "access plus 604800 seconds"
ExpiresByType application/x-javascript "access plus 604800 seconds"
ExpiresByType text/html "access plus 43200 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php
RewriteRule ^user\/(.*?)$ user.php?login=$1 [L,QSA]
RewriteRule ^show\/(.*?)$ show.php?id=$1 [L,QSA]
RewriteRule ^category\/(.*?)$ category.php?id=$1 [L,QSA]
RewriteCond %{REQUEST_URI} ^\/categories
RewriteCond %{QUERY_STRING} ^id=4$
RewriteRule .* /category/scripts? [L,R=301]
RewriteCond %{REQUEST_URI} ^\/categories
RewriteCond %{QUERY_STRING} ^id=5$
RewriteRule .* /category/programms? [L,R=301]
RewriteCond %{REQUEST_URI} ^\/categories
RewriteCond %{QUERY_STRING} ^id=6$
RewriteRule .* /category/mobile? [L,R=301]
RewriteCond %{REQUEST_URI} ^\/categories
RewriteCond %{QUERY_STRING} ^id=7$
RewriteRule .* /category/video? [L,R=301]
RewriteCond %{REQUEST_URI} ^\/categories
RewriteCond %{QUERY_STRING} ^id=8$
RewriteRule .* /category/audio? [L,R=301]
RewriteCond %{REQUEST_URI} ^\/categories
RewriteCond %{QUERY_STRING} ^id=9$
RewriteRule .* /category/books? [L,R=301]
RewriteCond %{REQUEST_URI} ^\/categories
RewriteCond %{QUERY_STRING} ^id=10$
RewriteRule .* /category/keys? [L,R=301]
RewriteCond %{REQUEST_URI} ^\/categories
RewriteCond %{QUERY_STRING} ^id=11$
RewriteRule .* /category/design? [L,R=301]
RewriteCond %{REQUEST_URI} ^\/categories
RewriteCond %{QUERY_STRING} ^id=12$
RewriteRule .* /category/other? [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule .* http://%1/$0 [L,R=301]

1 ответ 1

1

Сделайте так

RewriteCond %{REQUEST_URI} ^\/show$
RewriteCond %{QUERY_STRING} ^id=(.+)$
RewriteRule .* /show/%1? [L,R=301]

UPD

Все правила я вам переписывать не буду, но сам принцип отображу

RewriteEngine On

# удаляем www. из домена
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule .* http://%1/$0 [L,R=301]

# блок отвечающий за ссылки с show
RewriteCond %{REQUEST_URI} ^\/show$
RewriteCond %{QUERY_STRING} ^id=(.+)$
RewriteRule .* /show/%1? [L,R=301]

RewriteRule ^show\/(.*?)$ show.php?norewrite=yes&id=$1 [L,QSA]

# блок отвечающий за user
RewriteCond %{REQUEST_URI} ^\/user$
RewriteCond %{QUERY_STRING} ^login=(.+)$
RewriteRule .* /user/%1? [L,R=301]

RewriteRule ^user\/(.*?)$ user.php?norewrite=yes&login=$1 [L,QSA]

и так далее...
11
  • Не работает, в адрес добавляются show/708.php/708.php/708.php/708.php/708.php/708.php/708.php/708.php/.....
    – Rufex
    24 окт 2015 в 9:28
  • @Rufex, угу, смотрите, что у вас еще в .htaccess накалякано. У меня все работает: Ввожу localhost/show?id=708 получаю http://localhost/show/708 И .php в этом правиле переадресации ни где не дописывается!
    – Visman
    24 окт 2015 в 9:32
  • RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ $1.php
    – Rufex
    24 окт 2015 в 9:40
  • @Rufex, оформите свой вопрос полно, а не пишите уточнения в комментариях. А по поводу комментария: как оно может работать? У вас что, там реально существуют файлы 1.php, 2.php, ... 708.php? Спрашиваю, потому что больно уж странный редирект этот у вас.
    – Visman
    24 окт 2015 в 9:45
  • Это чтобы любой php файл вызывался без .php расширения
    – Rufex
    24 окт 2015 в 9:47

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими пользовательским соглашением, политикой конфиденциальности и политикой о куки

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.