【问题标题】:htaccess rewrite root to file with varaiblehtaccess 将根目录重写为带有变量的文件
【发布时间】:2015-06-05 01:53:17
【问题描述】:

我找到了大量关于 .htaccess 文件的教程,并且能够获得一些接近的东西:

Options +FollowSymLinks
RewriteEngine On 
RewriteRule ^HERE/(.*)$ /page1.php?id=$1 [NC]

现在这让我做
www.domain.com/HERE/35
但我想做
www.domain.com/35

我只希望它适用于根目录而不是文件夹根目录
当我删除“HERE”时,它显示缺少文件 404。

我仍然需要传递变量。

谢谢 安迪

【问题讨论】:

    标签: apache .htaccess mod-rewrite rewrite subdomain


    【解决方案1】:

    您需要添加一些条件,并可能使您的正则表达式更具限制性:

    Options +FollowSymLinks
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([0-9]+)$ /page1.php?id=$1 [NC,L]
    

    【讨论】:

      猜你喜欢
      • 2015-11-11
      • 1970-01-01
      • 1970-01-01
      • 2021-05-12
      • 1970-01-01
      • 1970-01-01
      • 2018-08-09
      • 2014-06-10
      • 2011-11-16
      相关资源
      最近更新 更多