1个用于多个php页面的mod-rewrite块

时间:2013-11-21 18:44:57

标签: php regex apache .htaccess mod-rewrite

我有两个详细信息页面:

 www.mymichiganforeclosures.com/detail.php?kfld=address_City_state_zip

 www.mymichiganforeclosures.com/landcontractdetail.php?kfld=address_city_state_zip

我需要一个mod_rewrite参数来传递php页面名称作为参数,第二个参数作为kfld传递查找参数。

以下.htaccess适用于detail.php:

options -multiviews
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+detail\.php\?kfld=([^\s&]+) [NC]
RewriteRule ^ /%1.html? [R=301,L]
RewriteRule ^([^.]+)\.html$ /detail.php?kfld=$1 [L,NC,QSA] 

我想要的是:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/(*)etail\.php\?kfld=([^\s&]+) [NC]
RewriteRule ^ /%1.html? [R=301,L]
RewriteRule ^([^.]+)\.html$ /$1etail.php?kfld=$2 [L,NC,QSA]

这可能在.htaccess吗?

OK!那怎么样:

if foreclosures
  RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+detail\.php\?kfld=([^\s&]+) [NC]
  RewriteRule ^ /%1.html? [R=301,L]
  RewriteRule ^([^.]+)\.html$ /detail.php?kfld=$1 [L,NC,QSA]  
else
  RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+LandContractsDetail\.php\?kfld=([^\s&]+) [NC]
  RewriteRule ^ /%1.html? [R=301,L]
  RewriteRule ^([^.]+)\.html$ /LandContractsDetail.php?kfld=$1 [L,NC,QSA]
endif

1 个答案:

答案 0 :(得分:2)

考虑以下代码:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/LandContractsDetail\.php\?kfld=([^\s&]+) [NC]
RewriteRule ^ /landcontracts/%1.html? [R=301,L]

RewriteRule ^landcontracts/([^.]+)\.html$ /LandContractsDetail.php?kfld=$1 [L,NC,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/detail\.php\?kfld=([^\s&]+) [NC]
RewriteRule ^ /foreclosures/%1.html? [R=301,L]

RewriteRule ^foreclosures/([^.]+)\.html$ /detail.php?kfld=$1 [L,NC,QSA]