php - .htaccess 重定向到错误页面

标签 php .htaccess mod-rewrite url-rewriting

这是原始网址

http://localhost/naranjeshaltd/index.php?url=home

我想将其重定向到

http://localhost/naranjeshaltd/home

我已经尝试过这个 htaccess 代码,但它将页面重定向到 http://localhost/xampp

Options +FollowSymLinks
RewriteEngine on

RewriteBase /naranjeshaltd
RewriteRule ^(.*)$ /index.php?url=$1 [L]

但是当我使用这个 htaccess 代码时一切正常

Options +FollowSymLinks
RewriteEngine on

RewriteBase /naranjeshaltd
RewriteRule home$ index.php?url=home 

但它是一个静态方法,我如何对所有页面执行此操作?

最佳答案

我在这里可以看到两个主要问题:

  1. 您应该避免重定向到 index.php 以获取真实的文件/目录/链接。
  2. 不要使用 / 作为目标 URL 中的起始斜杠,否则它将与您的 RewriteBase 不相关

将代码更改为:

RewriteBase /naranjeshaltd/

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

关于php - .htaccess 重定向到错误页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16243362/

相关文章:

php - 使用 GD 调整图像大小并将图像裁剪为白色背景的正方形

php - fullCalendar ignoreTimezone 似乎不起作用

php - 为什么前面没有 "https://"的URL会出现空白页?

.htaccess - 在我的重写和规则 .htaccess 文件上强制使用 HTTPS

php - 如何使用 PHP 在任何值中添加 .00?

php - session 变量 - mysqli_query 结果

regex - 使用 .htaccess 从 URL 中删除最后一个路径

php - 是否附加了 SEO 友好的 URL?

apache - htaccess 在重写规则中添加 @ 或空格时导致 500 内部错误

python - Django:从Apache mod_rewrite重定向时,错误的请求语法