我有一個 php 網站,加載頁面如下。
if ( $secretfile && file_exists( $moddir . $name . "/" . $secretfile . ".php" ) ) {
include_once( $moddir . $name . "/" . $secretfile . ".php" );
} else {
if ( isset( $_GET[ 'mod' ] ) ? $_GET[ 'mod' ] : '' ) {
$secretmodule = isset( $_GET[ 'mod' ] ) ? $_GET[ 'mod' ] : '';
if ( $secretmodule && file_exists( $moddir . $name . "/page.php" ) ) {
include_once( $moddir . $name . "/page.php" );
} else {
include_once( $moddir . "404.php" );
}
} else {
include_once( $moddir . "homepage.php" );
}
}
我正在使用 htaccess 來美化 url,如下所示。
RewriteRule ^([^/]*)/$ /index.php?mod=$1 [L]
RewriteRule ^([^/]*)/([^/]*)/$ /index.php?mod=$1&file=$2 [L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/$ /index.php?mod=$1&file=$2&proid=$3 [L]
我想在會話中添加語言,但我不想更改主要語言的 url(已編入索引)。只有其他語言會添加一個額外的變數。
eg:
main language(de) : www.site.com/module/file/ /index.php?mod=$1&file=$2 [L]
other lang (en) : www.site.com/en/module/file/ /index.php?lang=$1mod=$2&file=$3 [L]
other lang (fr) : www.site.com/fr/module/file/ /index.php?lang=$1mod=$2&file=$3 [L]
我只是不確定如何為這些配置設定 htaccess。
uj5u.com熱心網友回復:
您可以在 .htaccess 中擁有這些規則集:
RewriteEngine On
# ignore all files are directories from rules below
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# rules with any lang component
RewriteRule ^(en|fr)/([^/]*)/$ index.php?lang=$1&mod=$2 [L,QSA]
RewriteRule ^(en|fr)/([^/]*)/([^/]*)/$ index.php?lang=$1&mod=$2&file=$3 [L,QSA]
RewriteRule ^(en|fr)/([^/]*)/([^/]*)/([^/]*)/$ index.php?lang=$1&mod=$2&file=$3&proid=$4 [L,QSA]
# rules without any lang component
RewriteRule ^([^/]*)/$ index.php?lang=de&mod=$1 [L,QSA]
RewriteRule ^([^/]*)/([^/]*)/$ index.php?lang=de&mod=$1&file=$2 [L,QSA]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/$ index.php?lang=de&mod=$1&file=$2&proid=$3 [L,QSA]
uj5u.com熱心網友回復:
根據您顯示的嘗試,請嘗試以下操作。在您的情況下,確保您的 index.php 檔案和 htaccess 兩個檔案都存在于同一個檔案夾(根目錄)中。
請確保在測驗您的 URL 之前清除您的瀏覽器快取。
RewriteEngine ON
##Rules for en OR fr languages URLs to be rewritten in backend.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(en|fr)/([^/]*)/([^/]*)/?$ /index.php?lang=$1mod=$2&file=$3 [QSA,NC,L]
##Rules for links which are not started with en OR fr links.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ /index.php?lang=$1mod=$2&file=$3 [QSA,NC,L]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/445400.html
下一篇:用自己的屬性替換字典鍵
