2015-01-07 3 views
0

다시 작성하는이 같은 거의 같습니다htaccess로 301 리디렉션 + URL 내가 htaccess로있어

# disable directory browsing 
Options All -Indexes 

# start rewrites 
RewriteEngine on 

Redirect 301 /someoldpage.php http://example.com/fancyurl 

# if not a file, and not a directory, reroute through index as normal page 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L] 

내가 달성하고자하는 사람이 301 옛날에 액세스하려고 할 때 URL이 또한 다시 작성된다는 점이다 http://example.com/index.php?page=fancyurl

답변

0

Redirect이 mod_alias가의 일부이며, 재 작성 물건의 mod_rewrite의 일부가되는 동안 : http://example.com//someoldpage.php에 갈 때 redirectred URL이, 그래서 당신은 http://example.com/fancyurl 및 NOT 지금 좋아하는 URL을 참조하십시오. 두 개의 서로 다른 모듈이 동일한 요청에 적용되어 동시에 리다이렉션 및 재 작성을하게됩니다. 당신이 원하는 것은 요청의 index.php에 /someoldpage.pjp하지 재 작성이 경우 리디렉션 가지고, 그래서 당신은 단지 여기 mod_rewrite에 사용할 필요가 :

# disable directory browsing 
Options All -Indexes 

# start rewrites 
RewriteEngine on 

RewriteRule ^someoldpage\.php$ http://example.com/fancyurl [L,R=301] 

# if not a file, and not a directory, reroute through index as normal page 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L] 
0

내가이 문제를 치고있는 솔루션을 가지고 내 경우, 귀하의 htaccess에 다음 코드로 example.com/about.php에서 example.com/about으로 URL을 다시 쓰십시오.

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

## hide .php extension 
# To externally redirect /dir/foo.php to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] 
RewriteRule^%1 [R,L,NC] 

## To internally redirect /dir/foo to /dir/foo.php 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule^%{REQUEST_FILENAME}.php [L] 
+1

파일 확장명을 단절하려는 경우에는 작동하지만 (예 : 이전 링크/모두에 대한 이름이 변경된 페이지로 사람을 보내려는 경우에는 작동하지 않을 수도 있음) -us.php와 새 링크/about – Paul