【问题标题】:link taking me to directory due to htaccess rule由于 htaccess 规则,链接将我带到目录
【发布时间】:2014-01-24 12:26:48
【问题描述】:

当我点击一个特定链接时,它会将我带到目录文件列表,而不是它应该是的文件。

Click link -> Should go to: mysite.co.uk/services/exhibitions.php (A list page of exhibitions)
Takes me to ->mysite.co.uk/services/exhibitions/ (Directory overview)

我的目录列表是

mysite.co.uk/services/
mysite.co.uk/services/exhibitions.php
mysite.co.uk/services/exhibitions/exhibitions1.php
mysite.co.uk/services/exhibitions/exhibitions2.php

我知道它与我的 .htaccess 删除文件扩展名有关,我需要这个,但我不知道如何解决这个问题。有什么想法吗?

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]

最终的 url 应该类似于 mysite.co.uk/services/exhibitions/exhibitions1


Options +FollowSymLinks -MultiViews
Options +Indexes
AcceptPathInfo Off
RewriteEngine on
RewriteBase /

# Compress text files
<ifModule mod_deflate.c>
  <filesMatch "\.(css|js|x?html?|php)$">
    SetOutputFilter DEFLATE
  </filesMatch>
</ifModule>

# Expire headers
<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType image/x-icon "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
  ExpiresByType text/html "access plus 600 seconds"
  ExpiresByType application/xhtml+xml "access plus 600 seconds"
</ifModule>

# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
  <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
   <filesMatch "\.(css)$">
    Header set Cache-Control "max-age=604800, public"
   </filesMatch>
  <filesMatch "\.(js)$">
    Header set Cache-Control "max-age=216000, private"
   </filesMatch>
  <filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "max-age=600, private, must-revalidate"
  </filesMatch>
</ifModule>

 # BEGIN Turn ETags Off
<ifModule mod_headers.c>
 Header unset ETag
</ifModule>
FileETag None 

# BEGIN Remove Last-Modified Header
<ifModule mod_headers.c>
 Header unset Last-Modified
</ifModule>

#ErrorCodes
ErrorDocument 404 http://mysite.co.uk/404

# force non-www domain
RewriteCond %{HTTP_HOST} ^www\.mysite\.co.uk$ [NC]
RewriteRule (.*) http://mysite.co.uk/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]

【问题讨论】:

  • 这是唯一的规则还是还有更多的规则?
  • 不,我有压缩、重定向和其他一些位,让他们添加它们。虽然我很确定这是由于这条规则。
  • 确定在我的答案中尝试规则。

标签: .htaccess directory file-extension


【解决方案1】:

试试这个 PHP 扩展规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*)$ $1.php [L]

【讨论】:

  • 不幸的是,这没有奏效,给了我一个选择题
  • 这个multiple choice problem到底是什么。您能否详细说明什么不起作用以及您尝试了哪个 URL?
  • 我还没有摆脱多项选择问题,但我回到了第一方,我现在禁用了目录列表。我点击地址 mysite.co.uk/services/exhibitions.php,它会将我带到 mysite.co.uk/services/exhibitions/,这是一个普通用户出错,因为他们无法再访问它了。跨度>
  • 好吧,如果/exhibitions.php 在浏览器中变为/exhibitions,那么您还没有显示所有规则。将您的完整 .htaccess 放在您的问题中,看看您是否还有其他 .htaccess。
  • 我已经看到了,但目前在浏览器中有重定向规则:/services/exhibitions.php => /services/exhibitions。有没有.htaccess 是/services/ 目录呢?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-11-12
  • 1970-01-01
  • 1970-01-01
  • 2015-08-04
  • 2019-03-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多