Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用htaccess删除URL中的.html文件夹名称而不干扰js文件?_Javascript_Html_.htaccess_Url - Fatal编程技术网

Javascript 如何使用htaccess删除URL中的.html文件夹名称而不干扰js文件?

Javascript 如何使用htaccess删除URL中的.html文件夹名称而不干扰js文件?,javascript,html,.htaccess,url,Javascript,Html,.htaccess,Url,URL的格式: example.com/pages/contact.html 并且想要: example.com/contact 正在从URL中删除.html和文件夹 下面是一段简单的代码: RewriteEngine On #Here is the code for removing /pages/ and .html from url Options -MultiViews #Redirect any "direct" requests to the `/pa

URL的格式:

example.com/pages/contact.html
并且想要:

example.com/contact
正在从URL中删除
.html
和文件夹

下面是一段简单的代码:

RewriteEngine On


#Here is the code for removing /pages/ and .html from url

Options -MultiViews

#Redirect any "direct" requests to the `/pages` directory
#To remove the directory from the URL-path.
#Also removes the ".html" extension (if present)

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^pages(/.*?)(?:\.html)?$ $1 [R=301,L]

#Check if the requested resource exists in the /pages subdirectory.
#If so, rewrite the request to that subdirectory.
RewriteCond %{DOCUMENT_ROOT}/pages/$1 -f
RewriteRule (.+\.(css|js|png|jpg|gif))$ /pages/$1 [L]


#Check if the requested PHP file exists in the /pages subdirectory
#if requesting a URL that does not already have a file extension.
#NB: Assumes the URL-path does not otherwise contain dots.
#If so, rewrite the request to that subdirectory appending ".html"
RewriteCond %{DOCUMENT_ROOT}/pages/$1.html -f
RewriteRule ^([^.]+)$ /pages/$1.html [L]

#Here is the end of the code for removing /pages/ and .html from URL





#Here the code for removing index from the tool

RewriteBase /pages/tool1/

#remove index.php from URLs
#RewriteCond %{THE_REQUEST} /index\.html [NC]
#RewriteRule ^(.*?)index\.html$ $1 [L,R=302,NC,NE]

RewriteRule ^index\.html$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]

# Here is the end for removing index from the tool



#Here is the code for running even .html site to php

#HTID:15533125: DO NOT REMOVE OR MODIFY THIS LINE AND THE LINES BELOW

php_value display_errors 1

#DO NOT REMOVE OR MODIFY THIS LINE AND THE LINES ABOVE HTID:15533125:

AddHandler application/x-httpd-php .html .htm 

#Here is the end for running even .html site to PHP
这里有3个主要的代码块

  • 从URL中删除.html和/pages/folder

  • 从-example.com/tool1/index.php=>example.com/tool1这样的子文件夹中删除index.html

  • 也可以将run.html文件强制导入PHP

  • 现在,在.htaccess文件中实现了这段代码之后,它的工作方式很好,就像删除了tool1文件中的/pages/和index.html,还将.html运行到PHP中,但问题是,具有action属性的表单无法工作,javascript也无法运行

    我在主页的末尾有一个时事通讯部分[使用js向google sheets发送电子邮件,如教程所示],在那里接收电子邮件,但当我点击按钮时,它会再次重定向到主页,而且该工具不工作,看起来js没有应用


    请回答…

    当您使用SEO URL,如
    site.com/page/subpage
    时,它将破坏相对URL。这会导致脚本、CSS和图像无法加载(404未找到)。在
    之间添加
    。将“”替换为您的完整网站。请详细说明这一点?谢谢在页面上添加一个基本标记,如我上面所示。此基本标记修复了您的404问题。因此,我可以在HREF中使用/filename而不使用www.example.com。这是正确的。试试看。