【问题标题】:1 mod-rewrite block for multiple php pages1个用于多个php页面的mod-rewrite块
【发布时间】:2013-12-06 10:06:08
【问题描述】:

我有两个详细信息页面:

 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 中可行吗?

好的!这个呢:

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

【问题讨论】:

    标签: php regex apache .htaccess mod-rewrite


    【解决方案1】:

    考虑这段代码:

    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]
    

    【讨论】:

    • 尝试了该代码,但得到以下错误输出...mymichiganforeclosures.com/…
    • 这是它应该做的:mymichiganforeclosures.com/… 但它却进入了索引页面......
    • 尝试多个代码块会更好吗?一个用于detail.php,另一个用于landcontractdetail.php?
    • 是的,这也可以。但是在这两种情况下,.html URL 应该是什么?
    • 在任何一种情况下,输出的 url 都应该是 mymichiganforeclosures.com/address-city-state-zip.html - 没关系,因为页面上有特定的措辞......
    猜你喜欢
    • 1970-01-01
    • 2013-01-30
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多