我的 htaccess 规则不适用于实时服务器上的项目(htaccess 在文件夹内)
Posted
技术标签:
【中文标题】我的 htaccess 规则不适用于实时服务器上的项目(htaccess 在文件夹内)【英文标题】:My htaccess rule not wroking for a project on live server (htaccess is inside the folder) 【发布时间】:2017-01-30 12:19:24 【问题描述】:我想做什么:
在我的服务器上,我想通过 htaccess 编写 URL 重写规则(从 URL 中删除 .php 或 .html 扩展名)。
我的网站网址:
http://enacteservices.com/EpcGroup/
还有:
http://www.enacteservices.com/EpcGroup/contact
现在,如果您查看第二个 URL,.php 扩展名已被完美删除,但在页面存在时显示Page Not Found
。
如果我在那里写:http://www.enacteservices.com/EpcGroup/contact.php
它开始工作了。
我尝试在 .htaccess 中写入的内容(此文件在我的文件夹中):
首先
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /EpcGroup/
RewriteRule ^index\.php$ - [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %REQUEST_URI ^system.*
RewriteRule ^(.*)$ admin/index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %REQUEST_URI ^application.*
RewriteRule ^(.*)$ index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
第二个:添加(EpcGroup/):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /EpcGroup/
RewriteRule ^index\.php$ - [L]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %REQUEST_URI ^system.*
RewriteRule ^(.*)$ EpcGroup/admin/index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %REQUEST_URI ^application.*
RewriteRule ^(.*)$ EpcGroup/index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ EpcGroup/index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 EpcGroup/index.php
</IfModule>
但它不起作用。
我的根目录上有一个 .htaccess 有这样的编码:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
【问题讨论】:
这是给你的Reference,我得到的。 @Virb 我正在检查并尝试,但到目前为止还没有成功。我会更新 有人不断对我的所有问题投反对票 【参考方案1】:根据最近的评论,将根 .htaccess
更新为:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %REQUEST_URI !^/EpcGroup [NC]
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]
</IfModule>
和EpcGroup
目录中的那个:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /EpcGroup/
RewriteRule ^index\.php$ - [L]
RewriteCond %REQUEST_FILENAME.php -f
RewriteRule ^[^\.]+$ $0.php [NC,L]
RewriteCond %REQUEST_FILENAME.html -f
RewriteRule ^[^\.]+$ $0.html [NC,L]
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %REQUEST_URI ^system.*
RewriteRule ^(.*)$ admin/index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %REQUEST_URI ^application.*
RewriteRule ^(.*)$ index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
【讨论】:
@Anant 您的 wordpress 仍在控制您的其他路线。我不知道如何禁用 WP 这样做。不过,root htaccess 中的更改应该已经完成了。 我的错。你的解决方案对我有用。这是一个愚蠢的服务器重启问题。也很抱歉这么晚回复。感谢您的解决方案。以上是关于我的 htaccess 规则不适用于实时服务器上的项目(htaccess 在文件夹内)的主要内容,如果未能解决你的问题,请参考以下文章
.htaccess 适用于 Apache 服务器,但不适用于 FTP 目录
.htaccess 适用于 Apache 服务器,但不适用于 FTP 目录