2013-04-11 2 views
0

우리 웹 사이트에 깨끗한 URL을 만들고 싶습니다. 나는 이것을 어떻게 할 수 있었는지와 코드 스 니펫을 발견했다.하지만 내 요구 사항을 충족시키지 못한다. 여기서 우리는 기본적으로 원하는 것을 설명 할 것입니다. 우리는 사용자가 볼 수있는 특정 페이지를 나열하는 "페이지"메뉴를 가지고 http://www.test.comMod_rewrite - 깨끗한 URL 만들기

:

이 기본 웹 사이트의 URL입니다. 그것은처럼 보이는 다음 http://www.test.com/pages.php

우리는 기본적으로 누군가가 방문 할 때이 /pages.php/페이지로 리디렉션해야합니다 (또는 전체 URL과 함께 : test.com/pages를) 리디렉션하지 않거나 페이지를 표시하지 않습니다.

또한이 가능한 구성의 작업을해야합니다

  • /페이지
  • /페이지/
  • /page.php
  • 내가 Stackowerflow의 시스템을 살펴 보았다

하고, 우리가 실제로 원하는 방식으로 작동하고 있습니다. 그래서 나도 찾고 있어요 때마다 :

  • stackoverflow.com/questions
  • stackoverflow.com/questions/
  • stackoverflow.com/questions.php - 페이지를 표시 찾을 수없는 사이트

이것은 기본적으로 필요한 것입니다. 이 코드를 시도하지만, 내 요구에 완벽하게 작동하지 않습니다

Options +FollowSymlinks 
RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.+)$ /$1.php [L,QSA] 

내가 기뻐할 줄 사람이 달성 할 수있는 방법에 대한 명확한 설명을 쓸 수 있다면. 또한이 게시물이 중복 된 것을 발견하면이 정확한 질문을 검색했기 때문에 정확한 게시물을 연결하십시오. 그러나 이에 대한 답변을 찾지 못했습니다.

감사합니다.

+0

내 대답보기 [http : // stackoverflow.com/questions/14637335/url-re-writings-in-the-url에 여러 값이있을 때/14637516 # 14637516] (http://stackoverflow.com/questions/14637335/url) -rew-in-the-url/14637516 # 14637516) 및 [http://stackoverflow.com/questions/15496979/mod-rewrite-is-there]를 사용하여 -a-faster-way/15497491 # 15497491] (http://stackoverflow.com/questions/15496979/mod-rewrite-is-there-a-faster-way/15497491#15497491) – bitWorking

+0

나는 이것들을 씹었으며 그들은 http : //www.test.com/pages.php?id=123와 같은 URL에서 깨끗한 URL을 생성하는 방법에 초점을 맞추고 있습니다. 그러나 pages.php를/pages로 전환 할 수있는 솔루션이 있습니까? –

답변

-1

다른 게시물에서 이것을 발견했습니다. 그것은 분명히 URL에서 .php, .html, .cgi 확장자를 제거합니다. 다음은

RewriteCond %{REQUEST_URI} (.*)/$ 
RewriteCond %{REQUEST_FILENAME}\.html -f 
RewriteRule (.*)/$ $1.html [L] 

RewriteCond %{REQUEST_URI} (.*)/$ 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule (.*)/$ $1.php [L] 

RewriteCond %{REQUEST_URI} (.*)/$ 
RewriteCond %{REQUEST_FILENAME}\.cgi -f 
RewriteRule (.*)/$ $1.cgi [L] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.html -f [OR] 
RewriteCond %{REQUEST_FILENAME}\.php -f [OR] 
RewriteCond %{REQUEST_FILENAME}\.cgi -f 
RewriteRule .* %{REQUEST_FILENAME}/ [R=301,L] 
+0

파일에서 URL 확장자를 지우는 것이지, 보통의 패턴 인 데이터베이스에서 오는 SEO URL처럼 작동하지는 않습니다. –

0

, 첫 번째 규칙 것입니다 301 리디렉션 * .PHP과에 ".PHP"를 추가하여 다른 모든 URL을 처리 할 두 번째 규칙이없는 URL에 .PHP : 예를 들어

RewriteCond %{REQUEST_URI} ^/(.*?)\.php$ 
    RewriteRule ^/.*$ /%1 [R=301,QSA,L] 

    RewriteRule ^/(.*)$ /$1.php 

/page.php/page으로 리디렉션되며 page.php을 처리합니다.

+0

/page.php 또는/page 또는/page/ –

+0

이상하게도 내 컴퓨터에서 작동하지만 실제로 페이지에서 아무 것도하지 않습니다. 다른 규칙을 삭제 했습니까? – Walid

+0

Shoud 나는 이것들을 사용하고 있나? 다른 건 없니? –

0

좋아요, 다음과 같이 작성하십시오.

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName deli.localhost 

    DocumentRoot /var/www/deli/ 
    <Directory /var/www/deli/> 
     Options -Indexes FollowSymLinks MultiViews 
     AllowOverride None 
     Order allow,deny 
     allow from all 

       RewriteEngine on 

       ## Externally redirect clients directly requesting .(php|aspx|html|htm|pl|cgi|asp)+ page 
       ## URIs to extensionless URIs 
       ## If client request header contains php,aspx,html or htm file extension, redirect 
       ## It avoids an infinite loop since "THE_REQUEST" is what the UA asks for, not what the 
       ## server translates it to on the second pass. 
       ## THE_REQUEST syntax is something like: GET /page.html HTTP/1.0 
       RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.(php|aspx|html|htm|pl|cgi|asp)+(/.*)?\ HTTP [NC] 
       RewriteRule ^([^.]+)\.(php|aspx|html|htm|pl|cgi|asp)+(/.*)?$ http://xyz.com/$1$3 [NC,R=301,L] 


       FileETag none 





       ErrorDocument 401 /401.php 
       ErrorDocument 403 /403.php 
       ErrorDocument 404 /404.php 
       ErrorDocument 500 /500.php 
       ErrorDocument 503 /503.php 
    </Directory> 

    ErrorLog /var/log/apache2/error.log 

    # Possible values include: debug, info, notice, warn, error, crit, 
    # alert, emerg. 
    LogLevel warn 

    CustomLog /var/log/apache2/access.log combined 
</VirtualHost>