【问题标题】:htaccess Multiple Rewrite Rules Not Working In XAMPPhtaccess 多个重写规则在 XAMPP 中不起作用
【发布时间】:2018-11-20 01:32:52
【问题描述】:

我目前有两条规则:

首先将“domain.com/profile/user”替换为“domain.com/profile.php?user=user”

第二条规则从所有文件中删除 .php,以便无需 .php 即可访问它们。

这是 .htaccess 文件:

RewriteEngine On

RewriteBase /
RewriteRule ^profile/([^/]+)$ profile.php?user=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

在当前状态下,第一个规则有效,第二个无效。

但是,如果我将“Options +MultiViews”添加到顶部,则它是:

Options +MultiViews
RewriteEngine On

RewriteBase /
RewriteRule ^profile/([^/]+)$ profile.php?user=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

那么第一个规则不起作用而第二个起作用?

我只是不知道如何让它们都工作。

请注意,我正在为 Web 服务器使用 XAMPP 虚拟主机,并更改了相关设置以允许 htaccess 与 XAMPP 一起使用。

【问题讨论】:

    标签: php html .htaccess xampp


    【解决方案1】:

    好的,我找到了一个解决方案,虽然不是最好的,但很有效。

    我只是将我的 .php 移除器更改为另一个可以完成相同任务的版本。

    我不知道为什么这有效,而其他版本则无效。如果您知道为什么原来的那个不起作用,请告诉我。

    这是工作版本:

    RewriteEngine On
    
    
    RewriteBase /
    RewriteRule ^profile/([^/]+)$ profile.php?user=$1 [L,QSA]
    
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
    

    来源:https://www.digitalocean.com/community/questions/how-to-hide-php-extension-in-url-using-htaccess

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-11
      • 2017-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多