php - .htaccess 不适用于 php 包括

标签 php html .htaccess mod-rewrite

我正在尝试在我的 .htaccess 中使用 mod_rewrite,但没有用。

我的网址是 http://gestor.samfbas.com.br/index.php?p=something 应该是http://gestor.samfbas.com.br/something

该文件位于我的主机的一个子目录 (gestor) 中,所有文件都在该目录中。

<IfModule mod_rewrite.c>
Options +FollowSymLinks +Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?$ /index.php?p=$1 [L]
</IfModule>

最佳答案

试试这个(如果 index.php 在根文件夹 http://gestor.samfbas.com.br/index.php 中):

Options +FollowSymLinks
RewriteEngine On

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

这应该有效。在我的本地机器上测试它(没有其他服务器重定向,否则,只是一个新的 xampp 安装)。

它将 http://gestor.samfbas.com.br/something 重定向到 http://gestor.samfbas.com.br/index.php?p=something 无需更改浏览器中的 url。

除了评论中的问题。 此 URL 部分 p= 不应该被外部用户知道! 最好在这里使用长变量,例如 sadff34dngn4nil212ugn=,这样就没有人可以直接从外部调用带参数的 index.php。您无法 100% 阻止,但重定向参数 p= 仅供内部使用。

但这只是我对此的看法。

希望对您有所帮助。

找到去罗马的正确方法;)

关于php - .htaccess 不适用于 php 包括,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39512023/

相关文章:

php - 如何将android与phpmyadmin连接

javascript - 我的 pdf 文件一开始未被选中,仅在 Internet Explorer 中被选中

html - 在 Actionscript 3 项目中显示 HTML

javascript - &lt;input type ="text">与其后续元素<div>之间有空格。有没有办法让它们内联可见

php - .htaccess 在本地主机上给出 500 错误

php - 加号登录GET查询并比较URL

php - laravel 中的查询返回空响应

php - 是否可以从 Google 搜索中捕获搜索词?

php - 使用 php 从数据库中获取并显示多个复选框值

regex - 有关 htaccess 的书籍