거의 모든 프로젝트에서 작업하고 있는데 .htaccess와 관련된 일부 문제가 발생합니다. 나는 보통 가장 쉬운 해결책을 찾아 내고 아파치, 서버 등등에 대한 지식이나 이해력이 없기 때문에두고 간다. 그러나 이번에는 내가 너희에게 물어볼 것이라고 생각했다. .htaccess mod_rewrite 문제
이
내 (간체) 설정에서 파일과 폴더를 수 있습니다 :/modrewrite-test
.htaccess
/config
/inc
/lib
/public_html
.htaccess
/cms
/navigation
index.php
edit.php
/pages
index.php
edit.php
login.php
page.php
은 "설정", "INC"와 "LIB"폴더는 웹 사이트의 루트에서 "숨겨진"로 의미 . 나는 "public_html"로 사용자를 리디렉션하는 루트에서 .htaccess-file을 작성하여이를 수행하려고합니다. .htacess 파일에 다음이 포함되어 있습니다.
RewriteEngine On
RewriteRule (.*) public_html/$1
완벽하게 작동합니다. 내 브라우저에 "http://localhost/modrewrite-test/login.php"을 입력하면 내 의도 인 public_html/login.php로 끝납니다. 그래서 이것은 잘 작동합니다. "public_html을"의 htaccess로 파일이 포함되어 있습니다
이RewriteEngine On
# Root
RewriteRule ^$ page.php [L]
# Login
RewriteRule ^(admin)|(login)\/?$ login.php [L]
# Page (if not a file/directory)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ page.php?url=$1 [L]
첫 번째 재 작성 단지에 public_html을/page.php 내가 "http://localhost/modrewrite-test/을"에 도달하려고하면 저를 리디렉션합니다. 다음 재 작성은 로그인을 시도하는 사용자의 편의를위한 - 그들은 "http://localhost/modrewrite-test/admin을"접촉을 시도 또는 "http://localhost/modrewrite-test/login는"그들이 login.php 파일에 종료됩니다 그렇다면. 세 번째 및 마지막 다시 쓰기는 나머지 요청을 처리합니다. 내가 "http://localhost/modrewrite-test/bla/bla/bla을"에 도달하려고하면 그냥 "즐"등라는 이름의 폴더를 포함하는 대신라는 폴더 "라"를 찾는합니다 ('URL'로 GET 변수 설정)/page.php를 public_html이 저를 리디렉션합니다
이 모든 것들이 완벽하게 작동하지만 예를 들어 URL 끝에 슬래시가없이 "http://localhost/modrewrite-test/cms/navigation"에 도달하려고하면 경미한 문제가 발생합니다. 해당 페이지에 도달하려고하면 브라우저가 어떻게 든 "http://localhost/modrewrite-test/public_html/cms/navigation/"으로 리디렉션됩니다. 올바른 페이지가 표시되지만 URL이 리디렉션되고 URL에 'public_html'부분이 추가되는 이유는 무엇입니까? 원하는 동작은 URL이 그대로 유지되고 페이지 public_html/cms/navigation/index.php가 표시된다는 것입니다. 제 (간체)에서
파일과 폴더가 도움이 될 수 http://highbars.com/modrewrite-test.zip
아무런 변화가 없습니다. 강조하고있는 문제는 변경되지 않습니다. 또 다른 한가지는 "public_html"이라는 폴더에 "public_html"이라는 폴더가 없다면 http : // localhost/modrewrite-test/public_html/*에 접근 할 수 없어야한다는 것입니다. 간소화 된 설정). –