【问题标题】:URL Rewriting I don't want to show index.php in urlURL 重写我不想在 url 中显示 index.php
【发布时间】:2016-08-08 11:10:30
【问题描述】:

我正在运行我的 php 应用程序

http://localhost:8085/

我的目录结构是这样的: C:\wamp\www\网站

我已将 .htaccess 文件放在网站文件夹中。

<IfModule mod_rewrite.c>
#Turn on the RewriteEngine
RewriteEngine On
RewriteBase /website/
#Rules
RewriteRule ^(.*)$ index.php
</IfModule>

当我点击 index.php 时,它会将我带到 http://localhost:8085/ 主页,这是错误的,我想转到 http://localhost:8085/website

请指导我

【问题讨论】:

  • 另一个测试你可以重命名这个 .htaccess 然后再次点击链接看看问题是否得到解决。

标签: php .htaccess url-rewriting


【解决方案1】:

你需要在 index.php 之前添加你的website

RewriteRule ^(.*)$ /website/index.php

已更新,尝试完整代码,

RewriteEngine On
RewriteBase /website/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /website/index.php [L] 

注意:您需要在您网站中使用的每个链接中使用http://localhost:8085/website/作为基本URL,否则它将重定向到http://localhost:8085/

<a href="http://localhost:8085/website/index.php">Home page</a>

或者,不要在任何href 之前使用/,而是使用您的文件名,例如,

<a href="index.php">Home page</a>

如果您使用的是&lt;a href="/index.php"&gt;Home page&lt;/a&gt;,它将重定向到网址http://localhost:8085/的索引页面

你可以做一个虚拟主机直接访问https://httpd.apache.org/docs/current/vhosts/name-based.html

【讨论】:

  • 此更改网站未打开后出现内部服务器错误
  • 由于丹麦语使用的是RewriteBase /website/,因此规则中无需使用/website/index.php的完整路径。
  • 仍然是同样的问题,现在网站运行正常,但它正在将我重定向到本地主机
  • @DanishSubhu 你在使用像codeigniter这样的框架吗?如果是或不是,那么您需要使用 http://localhost:8085/website/ 作为您的基本 URL。
  • @anubhava 我有很多项目如果没有在 RewriteRule 中再次指定 RewriteBase 就无法工作。如果我将其从规则中删除,也会出现同样的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-29
  • 1970-01-01
  • 2013-06-25
  • 2013-09-15
  • 1970-01-01
  • 2016-03-18
相关资源
最近更新 更多