本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

Mod 重写:如何重写 URL 将所有内容传递给 index.php

发布于2023-09-20 21:25     阅读(1136)     评论(0)     点赞(10)     收藏(1)


我启用了 mod_rewrite 并使用 进行了检查phpinfo()

我放置了一个 .htaccess 文件

RewriteEngine on

RewriteRule ^(.*)$ index.php?/$1 [L]

以及 apache 根目录 (/var/www/html/) 中的 index.php 文件。

工作网址:

http://192.168.56.101/index.php

http://192.168.56.101/index.php/edrgderg

失败 (404) URL:

http://192.168.56.101/sgghsshgfhfgj

Mod_rewrite 应该将其形成为http://192.168.56.101/index.php/sgghsshgfhfgj,但事实并非如此。

我想将每个请求重定向到index.php.

解决方案:

我必须编辑我的 apache 配置:

sudo nano /etc/apache2/sites-enabled/000-default.conf

我补充道:

<Directory /var/www/html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
</Directory>

如此处建议的: https: //www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite-for-apache-on-ubuntu-14-04


解决方案


从重写规则中排除现有文件/目录以避免循环规则:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php?/$0 [L,QSA]


所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.phpheidong.com/blog/article/548961/5105225df55116f11942/

来源:php黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

10 0
收藏该文
已收藏

评论内容:(最多支持255个字符)