2010-06-09 1 views

답변

3

조금 자세한 :-) 사이트의 루트에있는 당신의 .htaccess 파일에 넣고 경우 폴 Peelan의 대답이 올바른지 :

RewriteEngine On 
RewriteRule ^users/(\d+)$ /users/?id=$1 

이 의지/users/33,/users/1,/users/12345 등과 일치하고/users /? id = 12345로 리디렉션됩니다.

이렇게하려면 Apache 구성에 mod_rewrite 엔진이 사용 가능해야합니다. 자세한 내용은 the mod_rewrite docs을 참조하십시오.

+0

부자 주셔서 감사합니다, 내가 필요한 것! – iamjonesy

+0

httpd.conf에서 RewriteEngine을 활성화해야한다고 생각하지만 어디에서 찾을 수 있을지 잘 모르겠습니다. 나는 Mac btw를 사용한다. 덕분에 – iamjonesy

+0

Mac에서는 어디에 있는지 모르지만'LoadModule rewrite_module/usr/lib/apache2/modules/mod_rewrite.so'와 같은 것이 필요합니다. 다시 쓰기 모듈을 특별히 활성화해야 할 수도 있습니다. 멈추는 경우 http://serverfault.com/이 서버 설정 probs를 묻는 더 좋은 장소 일 수 있습니다 :-) – richsage

2

"mod-rewrite"를 사용해야합니다. .htaccess 파일. 그러면 Apache는 .htaccess 파일의 설정에 따라 URL을 보냅니다.

예 :

다양한 다시 쓰기 규칙.

<IfModule mod_rewrite.c> 
    RewriteEngine on 

    # If your site can be accessed both with and without the 'www.' prefix, you 
    # can use one of the following settings to redirect users to your preferred 
    # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option: 
    # 
    # To redirect all users to access the site WITH the 'www.' prefix, 
    # (http://example.com/... will be redirected to http://www.example.com/...) 
    # adapt and uncomment the following: 
    # RewriteCond %{HTTP_HOST} ^example\.com$ [NC] 
    # RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] 
    # 
    # To redirect all users to access the site WITHOUT the 'www.' prefix, 
    # (http://www.example.com/... will be redirected to http://example.com/...) 
    # uncomment and adapt the following: 
    # RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] 
    # RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] 

    # Modify the RewriteBase if you are using Drupal in a subdirectory or in a 
    # VirtualDocumentRoot and the rewrite rules are not working properly. 
    # For example if your site is at http://example.com/drupal uncomment and 
    # modify the following line: 
    # RewriteBase /drupal 
    # 
    # If your site is running in a VirtualDocumentRoot at http://example.com/, 
    # uncomment the following line: 
    # RewriteBase/

    # Rewrite URLs of the form 'index.php?q=x'. 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] 
</IfModule> 

감사합니다, 폴

+0

에서 찾을 수 있습니다. 그런데 위의 예는 Drupal! –

+0

감사합니다 폴, http://www.phpriot.com/articles/search-engine-urls/2에서 좋은 기사를 찾았습니다. – iamjonesy

+0

좋아요! 다행스럽게 도울 수있어! /Paul –

0

이 질문에 대한 대답을 이미 선택했음을 알고 있습니다. 그러나이 사실을 알고 있으면 매우 유용합니다. PHP 프레임 워크 Codeigniter를 사용하면 기본적으로이 URL을 사용할 수 있습니다. 이 방법으로 URL을 다시 작성하는 것이 훨씬 쉽다는 것을 알게되었습니다. 코드 샘플을 포함하여 이에 대한 자세한 내용은 http://codeigniter.com/user_guide/general/urls.html