gpt4 book ai didi

.htaccess - 我的 htaccess 规则不适用于实时服务器上的项目(htaccess 在文件夹内)

转载 作者:行者123 更新时间:2023-12-01 04:53:03 30 4
gpt4 key购买 nike

我正在尝试做的事情:

在我的特定项目的服务器上,我想通过 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

最佳答案

根据最近的评论,更新根 .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>

关于.htaccess - 我的 htaccess 规则不适用于实时服务器上的项目(htaccess 在文件夹内),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39630266/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com