URL

2013-07-22 3 views
0

내가 내 orginal 한 URL을 내 원하는 URL이URL

http://www.example.com/products/pro-name 

처럼 올 것이다

http://www.example.com/products/product_detail.php?url=pro-name 

하지만 내가 부분적으로 URL을 함께 수행하고 htaccess로를 사용하여 내 URL을 다시 작성하고 내 경우에는 htacces를 사용하여 재 작성

http://www.example.com/products/product_detai/pro-name 

이 htaccess로 코드

를 사용하여
RewriteRule product_detail/url/(.*)/ product_detail.php?url=$1 
RewriteRule /(.*) product_detail.php?url=$1 

여기에 내 원하는 URL을 얻는 방법을 몰랐다. 욕망 URL을 얻는 누군가를 도우십시오. 감사합니다

답변

0
#Assuming the correct RewriteBase is used... 

#Redirect the client to the fancy url 
RewriteCond %{QUERY_STRING} ^url=(.*)$ 
RewriteRule ^product_detail\.php$ %1? [R,L] 

#Rewrite the url internally and stop rewriting 
#to prevent a loop 
RewriteRule ^(.*)$ product_detail.php?url=$1 [END] 

이 코드에서는 먼저 주소 표시 줄에 표시 할 URL로 클라이언트를 리디렉션합니다. %1은 RewriteCond의 첫 번째 캡처 그룹과 일치합니다. 후행 ?은 쿼리 문자열을 지 웁니다. 두 번째 규칙은 서버가 404 오류 대신 실제로 출력을 생성 할 수 있도록 url을 내부적으로 다시 작성합니다. END-flag (apache 2.3.9 이상에서 사용 가능, docs)는 URL 다시 쓰기를 완전히 중지합니다. 이것은 URL get이 끊임없이 재 작성되는 끝없는 루프를 막기위한 것입니다. (docs)

편집 : 2.3.9 아래의 아파치 버전은 최종 플래그가 없습니다. 루프를 방지하려면이를 해결해야합니다. 당신은 예를 들어 사용할 수 있습니다

#Assuming the correct RewriteBase is used... 

#Redirect the client to the fancy url 
RewriteCond %{QUERY_STRING} !redirect=true 
RewriteCond %{QUERY_STRING} ^url=(.*)$ 
RewriteRule ^product_detail\.php$ %1? [R,L] 

#Rewrite the url internally and stop rewriting 
#to prevent a loop 
RewriteRule ^(.*)$ product_detail.php?url=$1&redirect=true [L] 
+0

감사합니다. 하지만이 코드는 500 페이지 오류 –

+0

주어진 그냥 그것을 테스트하고 내 코드에 구문 오류가 없습니다. 당신은 2.3.9보다 작은 버전의 아파치를 사용하고있을 가능성이 높습니다. 미래의'END' 플래그는 아닙니다. 이 문제를 해결하거나 아파치 버전을 업그레이드해야합니다. – Sumurai8

1

mod_rewrite를 사용하고 httpd.conf을 통해 .htaccess로 다음 .htaccess에서 DOCUMENT_ROOT 디렉토리에이 코드를 넣어 : 귀하의 지원에 대한

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(products)/product_detail.php\?url=([^\s]+) [NC] 
RewriteRule^/%1/%2? [R=302,L] 

RewriteRule ^(products)/(.+?)/?$ /$1/product_detail.php?url=$2 [L,NC,QSA]