2016-07-30 3 views
0

나는 내가 예를 들어 정리할이htaccess로 Rediret 동적 URL이

localhost/sumar/gallery.php?gen=slug-here

같은 URL 구조가 : localhost/sumar/gallery/slug-here

그래서 난이 조건에 대한 규칙을 다시 작성할 필요하고 다른 사람이 기본 URL http://localhost/sumar/gallery.php?gen=slug-here에 자동으로 리디렉션하지 못하게합니다. localhost/sumar/gallery/slug-here

지금까지이 방법을 시도했습니다.

,
//that works 

RewriteRule ^Gallery/([A-Za-z0-9-_]+)/?$ gallery.php?gen=$1 

//below one does not seems to work 

RewriteCond %{THE_REQUEST} ^GET\ /sumar/gallery\.php\?gen=([\w-]+) [NC]  
RewriteRule ^sumar/gallery\.php$ /sumar/Gallery/%1? [R=301,L] 
+0

디렉토리 구조 란 무엇입니까? – hjpotter92

+0

.htaccess를 포함한 모든 파일은 –

답변

1

당신은 원시의 요청에 따라 행동해야 할 것 :

RewriteEngine On 

RewriteRule ^(sumar)/Gallery/([\w-]+)/?$ /$1/gallery.php?gen=$1 

RewriteCond %{THE_REQUEST} ^GET\ /sumar/gallery\.php\?gen=([\w-]+) [NC] 
RewriteRule ^sumar/gallery\.php$ /sumar/Gallery/%1? [R=301,L] 

PS를 : 캐릭터는 [A-Za-z0-9_]\w로 표현 될 수 설정합니다.

+0

루트에 있습니다.하지만 작동하지 않습니다. 실제로 http : //localhost/sumar/gallery.php? gen = sumar-shop과 같은 URL 구조가 있습니다. 정리하고 싶습니다. 예 : http : // localhost/sumar/gallery/sumar-shop 그래서이 조건에 대한 규칙을 다시 작성하고 누군가가 직접 gallery.php라는 기본 URL을 */gallery /로 리다이렉트하는 것을 막을 수는 없습니다. –

+1

@RahmanQaiser : 마지막 줄을'RewriteRule^gallery \ .php $/sumar/Gallery/% 1?로 변경 하시겠습니까? [R = 301, L]'그러나이 정보를 – anubhava

+0

@RahmanQaiser에 제공해야하며'.htaccess' 파일은 어디에 저장되어 있습니까? – hjpotter92