我的任务如下:我需要删除网址的主页index.php和所有网页的网址中的php。(目前我已经为所有页面设置了规范标签,以避免重复)。
尝试过的解决方案:我在这里查看了关于如何删除urls中的index.php和php的所有答案。
问题:然而,当我在htaccess中使用这两个解决方案时,只有一个有效。例如,使用上面的代码,我不能删除urls中的php。此外,它还会为某些页面生成404错误。你可以在这里看到:https://efficaceweb.fr/referencement-naturel-optimisation-site-seo
并创建了奇怪的URL:/index.php/audit-site-seo-referencement-naturel.php
有没有经验丰富的htaccess程序员能告诉我我的代码出了什么问题?我会非常非常感激的。提前谢谢。
<IfModule mod_rewrite.c>
#redirect from www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]
#remove php in url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
#remove index php in url
RewriteRule ^(.*)index\.php$ /$1 [R=301,NC]
#https redirect
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>我希望有重定向从index.php的主页和从.php的所有其他网页的工作,没有错误和奇怪的网址生成。谢谢
发布于 2019-08-03 20:51:36
要删除index.php,需要在href中添加以下内容
<a href="/"></a>而不是
<a href="/index.php"></a>要从url中删除.php,您需要将.htaccess放在根目录和根目录中
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [NC,L]然后从链接href中删除.php,如<a href="post"></a> remove .php
https://stackoverflow.com/questions/57338294
复制相似问题