0

わかりました、私は何時間もそれと戦ってきました。必要なことを行う 3 つの異なる .htaccess スクリプトがありますが、それらを混在させることはできません。

  1. (example.com/gallery.php -> example.com/gallery) からきれいな URL を作成します。

    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^([a-zA-Z0-9]+)$ $1.php
    
  2. #1 のスクリプトは example.com/index.php を example.com/index に転送するため、このコードは index.php を削除するので、example.com/index.php -> example.com

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?$1 [L,QSA]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
    RewriteRule ^ /%1 [R=301,L]
    
  3. スクリプトは末尾にスラッシュを追加する必要があるため、example.com/gallery -> example.com/gallery/

    # invoke rewrite engine
    RewriteEngine On
    RewriteBase /~new/
    
    # add trailing slash if missing
    rewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ $1/ [NC,R=301,L]
    

これらの 3 つのスクリプトを 1 つのユニバーサル URL スクリプトに結合するのを手伝ってくれる人はいますか

4

1 に答える 1

1

これらのディレクティブを Web サイトのルート ディレクトリにある .htaccess に追加します。

Options +FollowSymLinks
RewriteEngine On

# add trailing slash

RewriteCond %{REQUEST_URI} !(/$|\.) 
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] 

# rewrite gallery/ to gallery.php

RewriteCond %{REQUEST_URI} /$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1.php [L]

# redirect example.com/index.php to example.com/

RewriteCond %{REQUEST_URI} index\.php$
RewriteRule ^(.*)index\.php$ /$1/ [R=301,L]
于 2013-04-21T20:12:10.260 に答える