Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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
Regex htaccess删除.php、.html和尾部斜杠_Regex_Apache_.htaccess_Mod Rewrite_Rewrite - Fatal编程技术网

Regex htaccess删除.php、.html和尾部斜杠

Regex htaccess删除.php、.html和尾部斜杠,regex,apache,.htaccess,mod-rewrite,rewrite,Regex,Apache,.htaccess,Mod Rewrite,Rewrite,我正在尝试使用htaccess从url中删除.php.html和traling slash,但这段代码对php来说运行良好,但对html和trailing slash来说却不行 对于PHP RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] RewriteCond %{REQUEST_URI} !/system/.* [NC] RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L] # Directs

我正在尝试使用htaccess从url中删除.php.html和traling slash,但这段代码对php来说运行良好,但对html和trailing slash来说却不行

对于PHP

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
用于HTML

RewriteCond %{REQUEST_URI} index.html
RewriteRule ^(.*)index.html$ /$1/ [R=301,L]
这样做:

# externally redirect /dir/file.php to /dir/file and remove index
RewriteCond %{THE_REQUEST} \s/+(.*?/)?(?:index)?(.*?)\.(?:html?|php)/?[\s?] [NC]
RewriteRule ^ /%1%2 [R=301,L,NE]

# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]

# internally add php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

# internally add html extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.+?)/?$ $1.html [L]

RedirectMatch 301^(.*)/$/$1适用于我的尾部斜杠。谢谢您的回复,这里index.html url不适用于我,当我输入url时,就像它显示未找到页面一样,当我在浏览器中使用url时一样,所以出现了双斜杠。您能帮忙吗?请看更新,它将解决
/
问题。但是,对于
/index.html/web dev电子商务服务
,根据要求,它将重定向到
/web dev电子商务服务
,这是否没有发生?还是将其保留为
/index.html/web dev-ecommerce-services
本身?您好,谢谢,index.php和尾部斜杠现在工作正常,但是index.html不去,它没有重定向到/web dev电子商务服务,然而同样的事情在php上运行良好,但在index.html的情况下它不工作,这就是为什么我认为从
/index.html/web dev电子商务服务中剥离
index.html
不是一个好主意,顺便说一句,这确实是一个奇怪的URL。我在
index.php
中看到过类似的方案,但在
index.html
中没有看到类似的方案。搜索引擎优化人员说,当我们在url之间写入index.html时,它应该自动剥离。这在许多网站中都会发生,但在这里,当我使用您的代码编写index.php剥离时,index.html不会