【问题标题】:Friendly urls with htaccess in ads app广告应用中带有 htaccess 的友好网址
【发布时间】:2014-11-20 01:34:19
【问题描述】:

我目前正在运营一个分类广告网站, Php + Mysql(无框架) 基本上我有广告列表页面 (ads.php) 和广告详细信息页面 (ad_detail.php)

这是我当前的 .htaccess:

# disable directory browsing
Options All -Indexes

ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
ErrorDocument 502 /error.php
ErrorDocument 504 /error.php

RewriteEngine on

这是广告详情的重写规则:

RewriteRule ^(.*)-da([0-9]+)$ ad_detail.php?ad=$2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

最终的结果是这样的:

www.mysite.com/this-is-the-ad-detail-da50555(数字是广告ID)

或 www.mysite.com/another-ad-detail-da50777

我需要的是得到这个:

www.mysite.com/ads/another-ad-detail-da50777

RewriteRule ^([^\.]+)$ $1.php [NC,L]

我可以在其他网址中做些什么来显示 www.mysite.com/about/ 而不是 www.mysite.com/about(没有 /)

【问题讨论】:

    标签: php .htaccess mod-rewrite


    【解决方案1】:

    你可以有这样的规则:

    RewriteEngine on
    RewriteBase /
    
    RewriteRule -da([0-9]+)/?$ ad_detail.php?ad=$1 [L,QSA]
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
    RewriteRule ^(.+?)/?$ $1.php [L]
    

    【讨论】:

      猜你喜欢
      • 2012-04-27
      • 2012-10-15
      • 2016-03-11
      • 2017-05-14
      • 2014-07-26
      • 1970-01-01
      • 2016-02-02
      • 2013-08-10
      • 2010-10-24
      相关资源
      最近更新 更多