1

htacessでこれを作成する方法:

http://example.com/category => /index.php?action=category
http://example.com/category?query=string => /index.php?action=category&query=string
http://example.com/category/subcategory => /index.php?action=category/subcategory
http://subdomain.example.com => /index.php?action=subdomain
http://subdomain.example.com/category/subcategory => /index.php?action=subdomain/category/subcategory

これは私の現在のコードです:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)?$ /index.php?action=$1 [L]
4

2 に答える 2

0

以下の書き換えルールは書き換えます。

http://subdomain.domain.com => /index.php?action=subdomain/

index.php余分な書き換えルールを避けるために、それを自分で処理することをお勧めします。

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{HTTP_HOST} ^(subdomain)\. [NC]

RewriteRule ^(.*)$ /index.php?action=%1/$1 [L,QSA]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{HTTP_HOST} ^(domain)\. [NC]

RewriteRule ^(category)(^/.*)?$ /index.php?action=$1$2 [L,QSA]
于 2012-02-13T09:03:09.817 に答える
0

助けてくれてありがとう。

.htaccessコード:

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)?$ /index.php?action=$1 [L]

index.phpコード:

$domain = "domain.com";

if($_SERVER["HTTP_HOST"] != $domain)
{
    $subdomain = str_replace(".$domain","",$_SERVER["HTTP_HOST"]);
    $_GET['action'] = (isset($_GET['action'])) ? "$subdomain/".$_GET['action']:$subdomain;
}
于 2012-02-13T18:27:09.007 に答える