所以我试图用同一个文件夹设置两个不同的重写。这就是我想要做的......
这些网址
http://www.mywebsite.com/tshirts_bands http://www.mywebsite.com/tshirts_bands/some_band_name http://www.mywebsite.com/tshirts_bands/another_band
将使用以下文件:
http://www.mywebsite.com/bands.php http://www.mywebsite.com/bands.php?band=some_band_name http://www.mywebsite.com/bands.php?band=another_band
这是我试过的:
RewriteRule ^tshirts_bands$ /bands.php [L,QSA,NC]
RewriteRule ^tshirts_bands/([^.]+)$ /bands.php?band=$1 [L,QSA,NC]
如所提出的,这是我的完整信息:
ErrorDocument 404 /404.php
RewriteEngine On
# Matching any of 3 domains without www, and no subdomain
RewriteCond %{HTTP_HOST} ^(ni-dieu-ni-maitre|no-gods-no-masters|ni-dios-ni-amo)\.com$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteEngine On
RewriteRule ^images/([^/]+)_([^/]+)_([^/]+)/([^.]+)\.png$ /image_zoom.php?img=$1&color=$2&tshirt=$3&keywords=$4 [L,QSA,NC]
RewriteRule ^images_bestsellers/([^/]+)_([^/]+)_([^/]+)/([^.]+)\.png$ /image_bestseller.php?img=$1&color=$2&tshirt=$3&keywords=$4 [L,QSA,NC]
RewriteRule ^images_minis/([^/]+)/([^.]+)\.png$ /image_cache.php?a=$1 [L,QSA,NC]
RewriteRule ^images_minis_t/([^/]+)/([^.]+)\.png$ /image_mini.php?a=$1 [L,QSA,NC]
RewriteRule ^A-([0-9]+)/([^.]+)$ /tshirt.php?t=t-shirt-A$1 [L,QSA,NC]
RewriteRule ^bands_tshirts/([^/]+)/([^.]+)\.png$ /image_design.php?design=$2 [L,QSA,NC]
# RewriteRule ^tshirts_bands$ /bands.php [L,QSA,NC]
# RewriteRule ^tshirts_bands/([^.]+)$ /bands.php?band=$1 [L,QSA,NC]
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/tshirts_bands/?([^/]*)?/? [NC]
RewriteRule .* bands.php?band=%1 [L]
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
答案 0 :(得分:0)
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/tshirts_bands/?([^/]*)?/? [NC]
RewriteRule .* bands.php?band=%1 [L]
<强>更新强>
我已经测试了一些情况:
<?php //bands.php (testbox)
var_dump($_GET);
这是我的结果
//http://test.dev/tshirts_bands
//http://test.dev/tshirts_bands/
array (size=1)
'band' => string '' (length=0)
//http://test.dev/tshirts_bands/RedHotChiliPeppers
array (size=1)
'band' => string 'RedHotChiliPeppers' (length=18)
//http://test.dev/tshirts_bands/Slipknot
array (size=1)
'band' => string 'Slipknot' (length=8)
<强> UPDATE2 强> 你的.htaccess必须看起来像下面的代码:
####
# error handling
####
ErrorDocument 404 /404.php
####
# header handling
####
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
####
# url rewriting
####
RewriteEngine On
# Matching any of 3 domains without www, and no subdomain
RewriteCond %{HTTP_HOST} ^(ni-dieu-ni-maitre|no-gods-no-masters|ni-dios-ni-amo)\.com$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^images/([^/]+)_([^/]+)_([^/]+)/([^.]+)\.png$ /image_zoom.php?img=$1&color=$2&tshirt=$3&keywords=$4 [L,QSA,NC]
RewriteRule ^images_bestsellers/([^/]+)_([^/]+)_([^/]+)/([^.]+)\.png$ /image_bestseller.php?img=$1&color=$2&tshirt=$3&keywords=$4 [L,QSA,NC]
RewriteRule ^images_minis/([^/]+)/([^.]+)\.png$ /image_cache.php?a=$1 [L,QSA,NC]
RewriteRule ^images_minis_t/([^/]+)/([^.]+)\.png$ /image_mini.php?a=$1 [L,QSA,NC]
RewriteRule ^A-([0-9]+)/([^.]+)$ /tshirt.php?t=t-shirt-A$1 [L,QSA,NC]
RewriteRule ^bands_tshirts/([^/]+)/([^.]+)\.png$ /image_design.php?design=$2 [L,QSA,NC]
# RewriteRule ^tshirts_bands$ /bands.php [L,QSA,NC]
# RewriteRule ^tshirts_bands/([^.]+)$ /bands.php?band=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/tshirts_bands/?([^/]*)?/? [NC]
RewriteRule .* bands.php?band=%1 [L]