这是原始网址
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
但它是一个静态方法,我如何对所有页面执行此操作?
最佳答案
我在这里可以看到两个主要问题:
- 您应该避免重定向到
index.php
以获取真实的文件/目录/链接。 - 不要使用
/
作为目标 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/