【问题标题】:How to match URLs with .htaccess如何将 URL 与 .htaccess 匹配
【发布时间】:2012-04-09 15:59:44
【问题描述】:

我并没有真正使用过 .htaccess 文件,但我想知道如何匹配如下链接: http://localhost/test/pages/abc.php 类似于: http://localhost/test/abc

我想取出文件的扩展名并匹配 url。不重定向但匹配 url。

有没有办法做到这一点? 谢谢

【问题讨论】:

    标签: php javascript .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    应该这样做,首先它删除 .php 扩展名,然后从 url 中删除 pages/。

    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME}\.php -f 
    RewriteRule ^(.*)$ $1.php
    RewriteRule ^pages/(.+)$ http://www.yourblog.com/$1 [R=301,L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-06
      • 2013-05-05
      • 1970-01-01
      相关资源
      最近更新 更多