Javascript 如何使用htaccess删除URL中的.html文件夹名称而不干扰js文件?
URL的格式: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
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个主要的代码块
请回答…当您使用SEO URL,如
site.com/page/subpage
时,它将破坏相对URL。这会导致脚本、CSS和图像无法加载(404未找到)。在
和
之间添加
。将“”替换为您的完整网站。请详细说明这一点?谢谢在页面上添加一个基本标记,如我上面所示。此基本标记修复了您的404问题。因此,我可以在HREF中使用/filename而不使用www.example.com。这是正确的。试试看。