• 회원가입
  • 로그인
  • 구글아이디로 로그인

[서버] 서버 - URL RewriteRule (= 라라이트룰 = URL주소치환 = URL주소변경)

2,289  

 

1.

확장자 떼기

현재: https://homzzang.com/test.php

목표: https://homzzang.com/test

수정: https://homzzang.com/.htaccess

 

https://homzzang.com/test

 

RewriteEngine On

RewriteRule ^test?$ test.php

 


 

https://homzzang.com/dk

 

RewriteEngine On

RewriteRule ^dk?$ test.php

 


 

https://homzzang.com/dk.xml

 

RewriteEngine On

RewriteRule ^dk.xml?$ test.php

 

 

2.

쿼리단축 (1개)

현재: https://homzzang.com/user.php?id=1

목표: https://homzzang.com/user/1

수정: https://homzzang.com/.htacces

 

https://homzzang.com/user/1

 

RewriteEngine On

RewriteRule ^test?$ test.php

RewriteRule ^user/([0-9]+) user.php?id=$1 

 


 

https://homzzang.com/us/1

 

RewriteEngine On

RewriteRule ^test?$ test.php

RewriteRule ^us/([0-9]+) user.php?id=$1 

 



[파일소스]

https://homzzang.com/test.php

 

<?php

$i = 1;

while($i<=10){

    echo "<a href='user.php?id=$i'>User ".$i."</a><br>";

    $i++;

}

include 'style.css';

?>

 

cf. 참고

아래 소스 경우엔, user.php로 갔다가 다시 test.php로 바로 되돌아 옴.

echo "<a href='user/$i'>User ".$i."</a><br>";

 

 

[파일소스]

https://homzzang.com/user.php

 

<?php

if(!isset($_GET['id'])) {

    header('location: test.php');

}

else if(isset($_GET['id'])) {

    echo "User ID : ".$_GET['id']."<br>";

}

include 'style.css';

?>

 

 

 

3.

쿼리단축 (2개)

현재: https://homzzang.com/user.php?id=1&uid=2

목표: https://homzzang.com/user/1/2

수정: https://homzzang.com/.htacces

 

https://homzzang.com/user/1/2

 

RewriteEngine On

RewriteRule ^test?$ test.php

RewriteRule ^user/([[0-9a-zA-Z]+)/([0-9a-zA-Z]+) user.php?id=$1&uid=$2

 

 

 

[파일소스]

https://homzzang.com/test.php

 

<?php

$i = 1;

while($i<=10){

    $j = 99;

    echo "<a href='user.php?id=$i&uid=$j'>User ".$i."</a><br>";

    $i++;

}

include 'style.css';

?>

 

cf. 참고

아래 소스 경우엔, user.php로 갔다가 다시 test.php로 바로 되돌아 옴.

echo "<a href='user/$i/$j'>User ".$i."</a><br>";

 

 

[파일소스]

https://homzzang.com/user.php

 

<?php

if(!isset($_GET['id'])) {

    header('location: test.php');

}

else if(isset($_GET['id']) && isset($_GET['uid'])) {

    echo "User ID : ".$_GET['id']."<br>";
    echo "My ID : ".$_GET['uid'];

}

include 'style.css';

?>

 

 

 

 


분류 제목
JS-생코 JS 86강 - 상속 (2/3) : 상속의 사용방법
JS-생코 JS 85강 - 상속 (1/3) : 상속이란?
JS-생코 JS 84강 - this (5/5) : apply와 this
JS-생코 JS 83강 - this (4/5) : 객체로서 함수
JS-생코 JS 82강 - this (3/4) : 생성자와 this
JS-생코 JS 81강 - this (2/5) : 메소드와 this
JS-생코 JS 80강 - this (1/5) : 함수와 this
JS-생코 JS 79강 - 전역객체
JS-생코 JS 78강 - 생성자와 new (3/3) : 생성자와 new
JS-생코 JS 77강 - 생성자와 new (2/3) : 객체생성
JS-생코 JS 76강 - 생성자와 new (1/3) : 소개
JS-생코 JS 75강 - 객체지향프로그래밍 (3/3) : 부품화
JS-생코 JS 74강 - 객체지향프로그래밍 (2/3) : 추상화
JS-생코 JS 73강 - 객체지향프로그래밍 (1/3) : 오리엔테이션
JS-생코 JS 72강 - 함수의 호출 (2/2) : apply의 사용
JS-생코 JS 71강 - 함수의 호출 (1/2) : apply 소개
JS-생코 JS 70강 - arguments (2/2) : function length
JS-생코 JS 69강 - arguments (1/2) : arguments란?
JS-생코 JS 68강 - 클로저 (closure) 4/4 : 클로저의 응용
JS-생코 JS 67강 - 클로저 (closure) 3/4 : private variable
23/35
목록
찾아주셔서 감사합니다. Since 2012