내 코드 :이 작동다시 쓰기는 디렉토리에서 작동합니다. 그러나 파일이 아닌
RewriteEngine on
RewriteBase/
RewriteRule ^article/([a-z]+)/?$ /index.php?page=article&name=$1 [L]
RewriteRule ^([a-z]+)/?$ /index.php?page=$1 [L]
. 하지만 파일 이름이나 디렉토리를 제공하면 실패합니다.
내가 원하는 무엇 : 사용자가 디렉토리 나 파일 이름을 요청하면
는- 는 홈 페이지로 리디렉션합니다.
다른,이 규칙은 평가되어야한다 :
RewriteRule ^article/([a-z]+)/?$ /index.php?page=article&name=$1 [L]
는RewriteRule ^([a-z]+)/?$ /index.php?page=$1 [L]
내 사이트의 루트에있는 하나 개의 index.php 파일이 있습니다 : "http://mysite.com/index. PHP는 "
샘플 요청 :
User typed url --- Physical matched url --- Comments
----------------------------------------------------------
http://mysite.com/cinema --- http://mysite.com/index.php?page=cinema --- display cinema page
http://mysite.com/contacus --- http://mysite.com/index.php?page=contactus --- display contact us page
http://mysite.com/article/iphone --- http://mysite.com/index.php?page=article&name=iphone --- display article
http://mysite.com/images --- http://mysite.com/index.php --- redirect to index page, because it is a physical directory
http://mysite.com/js --- http://mysite.com/index.php --- redirect to index page, because it is a physical directory
내 이상적 상대 동맹 코드 :
RewriteEngine on
RewriteBase/
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)/$/[R,L]
RewriteRule ^article/([a-z]+)/?$ /index.php?page=article&name=$1 [L]
RewriteRule ^([a-z]+)/?$ /index.php?page=$1 [L]
위 코드를 사용하면 부분적으로 작동합니다. 즉
http://mysite.com/images --- http://mysite.com/?page=images is displayed in address bar
http://mysite.com/images/ --- http://mysite.com/ is displayed in address bar
내가 두 번째 조건 (첫 번째 조건의 라인 후)로 RewriteCond %{REQUEST_FILENAME} -f
를 사용
감사하지만 그것은 효과가 없었습니다. 나는이 간단한 문제 때문에 정신적으로 우울한 상태입니다. 내 모든 스크립트는 문제없이 작동하지만이 URL 재 작성 만 문제가됩니다. 나는 해결책을 찾기 위해 몇 시간을 소비 해왔다. :( –