【问题标题】:.htaccess RewriteRule for single file besides index.php.htaccess RewriteRule 用于除 index.php 之外的单个文件
【发布时间】:2018-03-04 12:34:37
【问题描述】:

我正在尝试为单个文件 viewprofile.php 编写一个 .htaccess 脚本,它有一个参数,但这似乎不起作用:

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^viewprofile$ viewprofile.php?mem=$1 [QSA, L]
RewriteRule ^viewprofile$ /viewprofile.php?mem=$1 [QSA, L]

RewriteRule ^([a-zA-Z0-9-\w]+)$ index.php?p=$1
RewriteRule ^([a-zA-Z0-9-\w]+)/$ index.php?p=$1

理想情况下,我希望结果显示为 www.example.com/viewprofile/JHFSD667 而不会干扰 index.php 文件。 viewprofile.phpindex.php 都在同一个目录中。

【问题讨论】:

    标签: php .htaccess


    【解决方案1】:

    您必须删除[QSA, L] 中的空格。

    然后您必须添加一个捕获组才能将配置文件放入mem

    或者,您可以通过添加/? 仅对index.php 使用一条规则。

    RewriteRule ^viewprofile/([\w\d]+)$ viewprofile.php?mem=$1 [QSA,L]
    RewriteRule ^([a-zA-Z0-9-\w]+)/?$ index.php?p=$1
    

    【讨论】:

      猜你喜欢
      • 2016-08-20
      • 2023-04-03
      • 2014-10-03
      • 2012-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-07
      相关资源
      最近更新 更多