【问题标题】:How to put index/ in DirectoryIndex? .htaccess如何将 index/ 放入 DirectoryIndex? .htaccess
【发布时间】:2014-04-02 01:25:57
【问题描述】:

如何将 index/ 放入 directoryIndex?

当我访问这个 url localhost/mywebsite/ 我的网站没有正确安排 但是当我把 localhost/mywebsite/index/ 它工作正常。

这是我的 htaccess 文件

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

DirectoryIndex index.php index.php3 index.html index.htm index/ <-- i add this

提前致谢:)

附言。 localhost/mywebsite/index/ = localhost/mywebsite/index.php 我只是将我的网页的文件扩展名隐藏到/(斜线)。

【问题讨论】:

  • 您的问题有误;您问题中的两个有效网址都是localhost/mywebsite/
  • 您还可以详细说明您的实际问题,而不是“未正确安排”。
  • 抱歉。 localhost/mywebsite/index/ 我的意思是这个:D

标签: php .htaccess


【解决方案1】:

提供DirectoryIndex 是没有任何意义的,它是一个文件 列表,在直接访问目录 的情况下提供服务,另一个目录.您可能只想将所有内容重写到该目录。

假设你的 htaccess 文件在/mywebsite/ 目录下,那么把这个加到最上面:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/mywebsite/index
RewriteRule ^$ /mywebsite/index/ [L]

所以它看起来像:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/mywebsite/index
RewriteRule ^$ /mywebsite/index/ [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

DirectoryIndex index.php index.php3 index.html index.htm

【讨论】:

  • 我隐藏了我的文件扩展名,从.php到/(斜杠),localhost/mywebsite/index/ = localhost/mywebsite/index.php,通常当我们访问localhost/mywebsite/时我们重定向在 localhost/mywebsite/index.php 上,对吗?当我访问 localhost/mywebsite/ 时的问题没有找到所有图像。
  • 我想要发生的是当我访问我的 localhost/mywebsite/ 时找到所有图像,否则它将重定向到 localhost/mywebsite/index/ :)
猜你喜欢
  • 2013-01-15
  • 2023-03-22
  • 1970-01-01
  • 1970-01-01
  • 2015-12-24
  • 2023-03-03
  • 1970-01-01
  • 2013-10-27
  • 2018-05-18
相关资源
最近更新 更多