【问题标题】:apache2 mod_rewrite not working for index.phpapache2 mod_rewrite 不适用于 index.php
【发布时间】:2013-11-09 11:09:37
【问题描述】:

我正在做一个需要像藤蔓一样的链接的项目。

我发现这可以通过名为 mod_rewrite 的 apache 2 模块来完成。所以,我创建了.htaccess 文件并放在root/v/

.htacess 代码

Options +FollowSymLinks
RewriteEngine On
RewriteBase /c/
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^c/(.*)$ index.php?page=$1 [L,QSA]

在文件夹/root/v/ 中有一个名为index.php 的脚本,它接受一个名为page 的变量。有了这个,我希望我可以做类似的事情:

http://webpage.com/c/tw3fN2

apache 会调用链接

http://webpage.com/c/index.php?page=tw3fN2

但我不工作。我在这里犯了什么错误或忘记了一些简单的事情。

【问题讨论】:

  • 所以您已将 htaccess 文件放在名为 v 的目录中,并尝试通过名为 c 的路径访问它?

标签: apache .htaccess mod-rewrite ubuntu amazon-ec2


【解决方案1】:

修复了 .htaccess 文件中的以下错误并将文件放在根目录中

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  ^/c/([^/]+)/?$    [NC]
RewriteRule .*       c/index.php?key=%1 [L]

感谢大家的回复。 欣赏它

【讨论】:

    猜你喜欢
    • 2010-12-20
    • 2023-04-08
    • 2019-07-08
    • 1970-01-01
    • 2012-09-30
    • 2013-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多