【问题标题】:Htaccess code redirects to XAMPP index pageHtaccess 代码重定向到 XAMPP 索引页面
【发布时间】:2015-08-13 06:01:08
【问题描述】:

我正在尝试编写 htaccess 代码,将除直接链接文件(例如图像和 css 文件)之外的所有 URL 重定向到我的 index.php 文件进行处理

http://localhost/testsite/login

重定向到

http://localhost/testsite/index.php?cmd=login

但是 htaccess 代码将我重定向到 XAMPP 主页。这是我的 htaccess 代码

DirectoryIndex index.php

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?cmd=$1  [QSA,NC,L]

我做错了什么?

【问题讨论】:

  • RewriteBase /testsite/

标签: php apache .htaccess mod-rewrite redirect


【解决方案1】:

从目标中删除/并使用正确的RewriteBase

DirectoryIndex index.php
RewriteEngine on
RewriteBase /testsite/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?cmd=$1  [QSA,L]

/index.php 会将其路由到站点根目录index.php,而不是当前目录中的index.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 2016-08-30
    • 2013-10-20
    相关资源
    最近更新 更多