2013-07-02 11 views
1

다음 문제가 발생했습니다. 이 URL이 www.mysite.com/inde.php?SomePageName 이며 www.mysite로 다시 작성하고 싶습니다. .com/SomePageName URL을 params (예 : mysite.com/index.php 또는 mysite.com/index.php)없이 호출하면 index.php를 제거하고 싶습니다.URL에서 index.php 및 index.php 쿼리 문자열을 제거하십시오.

내 htaccess로 파일을 mysite.com/로 리디렉션해야 할 것은 다음과 같습니다

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(index\.php)?\?([^&\ ]+) 
RewriteRule^/%2? [L,R=302] 
RewriteRule ^index.php$ http://www.mysite.com/ [R=302,L] 

는 이제 때문에 마지막 선언의 루프를하고있어.

나는 이것을 달성 할 수있는 방법이 있습니까?

감사

PS : 그것은 나 이후 인 경우

Options +FollowSymLinks 
RewriteEngine on 

RewriteRule ^cumpara-(.*)-(.*)\.html$ index.php?Profile&ID=$2 [L] 
RewriteRule ^lista-scut-motor-metalic-(.*)-(.*)-(.*)\.html$ index.php?List&SubID=$3&Categorie=$1&Subcategorie=$2 [L] 
RewriteRule ^scut-motor-metalic-(.*)-(.*)\.html$ index.php?ViewCat&CatID=$2 [L] 
RewriteRule ^foto-(.*)-(.*).jpg$ includes/timthumb.php?src=data/$1/$2.jpg&w=300&q=100 [L] 
RewriteRule ^product-(.*)-(.*).jpg$ includes/timthumb.php?src=data/$1/$2.jpg&w=530&q=100 [L] 
RewriteRule ^side-(.*)-(.*).jpg$ includes/timthumb.php?src=data/$1/$2.jpg&w=175&h=110&q=100 [L] 
RewriteRule ^zoom-(.*)-(.*).jpg$ data/$1/$2.jpg [L] 

RewriteCond %{REQUEST_URI} ^/index.php$ 
RewriteCond %{QUERY_STRING} !^$ 
RewriteCond %{QUERY_STRING} ^(.*)$ 
RewriteRule ^.*$ http://www.mysite.com/%1/? [R=302,L] 

RewriteRule Despre index.php?Despre [L] 
RewriteRule Help index.php?Help [L] 
RewriteRule Livrare index.php?Livrare [L] 
RewriteRule Contact index.php?Contact [L] 

RewriteCond %{HTTP_HOST} ^mysite.com$ 
RewriteRule ^(.*)$ "http\:\/\/www\.mysite\.com\/$1" [R=301,L] 

ErrorDocument 404 /404.html 

답변

1

는, 가장 간단한 솔루션은 PHP

이 htaccess로를 갖는 통해 index.php에의 중복을 처리하는 것이 었습니다 전체 htaccess로 :

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

모든 REQUEST_URI는 PHP로 작성되므로, 전자의 index.php가 존재하고 있는지, 다음이 아닌 index.php를 링크로 리디렉션 : D를이 같이 :

if(strpos($_SERVER['REQUEST_URI'], "?") !== FALSE) { 
    $checkq = explode("?", $_SERVER['REQUEST_URI']); 
    $vars = "?".$checkq[1]; 
    $checkq = $checkq[0]; 
}else { 
    $checkq = $_SERVER['REQUEST_URI']; 
    $vars = ''; 
} 
if(strpos($checkq, "/") !== FALSE) { 
    $link = explode("/", $checkq); 

    if($link[1] == "index.php"){ 
     unset($link[1]); 
     $link = implode("/",$link); 

     header('Location: http://'.$_SERVER['HTTP_HOST'].$link.$vars); 
     exit(); 
     } 
} 

이도 당신과 함께 작동합니다 변수/사용자 정의의 .htaccess를 가져옵니다.

관련 문제