2016-10-30 4 views
0

내 URL에 1 개의 변수 또는 때로는 2 개의 변수가 있어야합니다. 수정 모드가 올바르게 작동하지 않습니다.

http://example.com/home 
or http://example.com/home/hr 

나는 public_html 폴더에 다음과 같은 .htaccess 파일을 만든 : 그것은 작동하지 않습니다

RewriteEngine On RewriteRule ^([a-zA-Z0-9]+)$ index.php?page=$1 
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?page=$1 ReWriteRule 
^([^/]+)/(\d+)/? index.php?page=$1&q=$2 

!

include("view/hr.php") 

것은 이제 index.php 페이지 변수를 가지고 있으며, /view/hr.php는 2 변수를 가지고 : 지금 hr.phpindex.php에 포함되어 public_html/view

public_htmlhr.php에서 index.php을해야합니까.

어떻게 작동합니까?

답변

0

로직을 .htaccess에 넣지 말고 정적 파일을 제외한 모든 것을 하나의 PHP 파일로 다시 작성한 다음 요청을 그 안에 라우팅하십시오. 예컨대 :

# only rewrite static file URLs when not found, otherwise let them through 
RewriteCond $0 !^(?:js|css|img|video|audio)$ [OR] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond ^[^/]+ index.php 

지금, index.php, 당신은 $_SERVER['REQUEST_URI']의 URL을 가지고 있고 당신이 원하는 모든 파일을 포함 할 수 있습니다.

+0

나를 위해 일하지 못했습니다! : – user2305672

+0

정확하게 작동하지 않는 것은'index.php'가 전혀 호출되지 않았습니까?'RewriteEngine'이'On'인지 확인 했습니까?'$ _SERVER [ 'REQUEST_URI']'의 값을 확인 했습니까? – Walf

관련 문제