2

다음 htaccess 코드를 사용하여 URL을 깨끗한 URL로 리디렉션하지만, 이제는 원래 URL을 새 정리 URL로 리디렉션해야합니다.stackoverflow.com URL과 같은 데이터베이스 값을 쿼리하여 리디렉션

원본 URL :

example.com/search/store_info.php?store=113&dentist=Dr.%20John%20Doe 

청소 URL : 나는 "CLEAN URL로 리디렉션 할 수있는"ORIGINAL URL "입니다 무엇이 필요

example.com/search/113/dr-john-doe 

". 이유가 필요한 이유는 두 URL이 모두 Google 검색에 나타나기 때문입니다.

원래 URL 만 사용하면 클린 URL로 자동 리다이렉트해야합니다. 그것은 현재 그렇게하지 않습니다.

여기 내 htaccess 파일입니다. 나는 RedirectMatch에 대해 읽은

ErrorDocument 404 default 

<IfModule mod_rewrite.c> 
Options -MultiViews 
RewriteEngine On  
RewriteBase /search/ 

RewriteCond %{QUERY_STRING} . 
RewriteCond %{THE_REQUEST} /store_info\.php\?store=([a-z0-9]+)&dentist=([^\s&]+) [NC] 
RewriteRule^%1/%2/? [L,NE,R=301] 

RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d [OR] 
RewriteCond %{REQUEST_URI} \.(?:jpe?g|gif|bmp|png|ico|tiff|css|js)$ [NC] 
RewriteRule^- [L] 

RewriteRule ^([a-z0-9]+)/([^\s.]*)[.\s]+(.*)$ $1/$2-$3 [NC,DPI,E=DONE:1] 

RewriteCond %{ENV:DONE} =1 
RewriteRule ^([0-9a-z]+)/([^\s.]+)$ $1/$2 [R=301,NE,L] 

RewriteRule ^([a-z0-9]+)/([a-z0-9-]+)/?$ store_info.php?store=$1&dentist=$2 [QSA,L,NC] 

</IfModule> 

그러나 나는 여기서 내 htaccess로 파일로 구현하는 방법을 모른다.

+0

가 리디렉션되지 않습니다 @anubhava .. 내가 example.com/search/store_info.php'로 이동, 그래서 만약 가게를 = 113'를 빼고 " & dentist = Dr. % 20John % 20Doe "URL에서 원래 URL로 이동하고 클린 URL 버전으로 변환하지 않습니다. 'example.com/search/store_info.php? store = 113'도 깨끗한 URL로 이동하는 곳으로 변경하려고합니다. 'Redirect 301 /search/store_info.php?store=118 http : // www.example.com/search/118/John-Doe-Dental-Group/' – antivinegar

+0

나는' & dentist = Dr. % 20John % 20Doe'는 이전 페이지의 버튼으로 URL 문자열에 추가됩니다. 그래서'example.com/search/ store_info.php? store = 113'은 URL로부터 치과의 사 이름을 붙잡고 htaccess 파일을 사용하여 깨끗한 URL을 만드는 원래의 URL입니다. – antivinegar

+0

@anubhava 그래서 [this]와 같이 할 방법이 없습니다. (http://stackoverflow.com/questions/38453161/rewriting-old-urls-to-pretty-urls-and-redirect-old-urls- to-new-with-htaccess)? web.config 파일에 방법이 있다는 것을 알고 있습니다. 하지만 htaccess에서 알아낼 수는 없습니다. – antivinegar

답변

1

이 같은 코드를 가지고 :

<?php 
$store = $_GET['store']; 

if (empty($store)) { 
    header("HTTP/1.1 404 Not Found"); 
    exit; 
} 

$dentist = $_GET['dentist']); 

// pull dentist from DB by store id. Create this function in PHP and 
// query your database 
$dentistFromDB = preg_replace('/[\h.]+/', '-', $row['businessName']); 

// DB returns an empty or no value 
if (empty($dentistFromDB)) { 
    header("HTTP/1.1 404 Not Found"); 
    exit; 
} 

// DB returned value doesn't match the value in URL 
if ($dentistFromDB != $dentist) { 
    // redirect with 301 to correct /<store>/<dentist> page 
    header ('HTTP/1.1 301 Moved Permanently'); 
    header('Location: /' . $store . '/' . $dentistFromDB); 
    exit; 
} 

// rest of the PHP code should come now 

?> 
0

임의의 규칙/지시어로 htaccess 파일을 혼란스럽게 처리 할 필요가 없습니다. %{THE_REQUEST}이 일치하고 나중에 %{ENV=DONE} 조건이있는 현재 규칙 집합이 충분합니다.

Google에서 페이지를 다시 크롤링하기까지 며칠 기다려주십시오. 오래된 더러운 URL은 사라집니다. 또한 Google 웹 마스터 도구에서 검색하여 수동으로 실행할 수 있는지 확인할 수도 있습니다.

추신 : 첫 번째 규칙에서 RewriteCond %{QUERY_STRING} . 행을 삭제할 수 있습니다. 당신의 store_info.php 내부