Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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
Apache 如何删除.html并在url末尾添加斜杠_Apache_.htaccess_Url_Url Redirection - Fatal编程技术网

Apache 如何删除.html并在url末尾添加斜杠

Apache 如何删除.html并在url末尾添加斜杠,apache,.htaccess,url,url-redirection,Apache,.htaccess,Url,Url Redirection,我一直在尝试删除.html扩展名,并在URL栏的末尾添加一个斜杠 我有下面这样的例子 因此,如果有人进来: example.com--转到--example.com/ example.com/index.html--转到-example.com/ example.com/index--转到--example.com/ 及 example.com/first-page.html--转到--example.com/main-page/但以example.com/main-page的形式出现 exam

我一直在尝试删除.html扩展名,并在URL栏的末尾添加一个斜杠

我有下面这样的例子

因此,如果有人进来:

example.com--转到--example.com/

example.com/index.html--转到-example.com/

example.com/index--转到--example.com/

example.com/first-page.html--转到--example.com/main-page/但以example.com/main-page的形式出现

example.com/parent-page/index.html--转到--example.com/parent-page/(工作)

example.com/parent-page/child-page.html/--转到--example.com/parent-page/child-page/,但显示为example.com/parent-page/child-page

这是我的.htaccess,我想在url的末尾添加尾随斜杠

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^/]+)/$ $1.html 

# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

任何人都可以帮助我,我将非常感激。

如果您想从html文件中删除.html扩展名,例如,yoursite.com/wallpaper.html到yoursite.com/wallpaper,您只需更改上面代码的最后一行以匹配文件名

删除Extensions.html 在末尾添加尾部斜杠 有关更多参考,请单击

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.html
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]