gpt4 book ai didi

.htaccess - 将 .php URL 重定向到不带扩展名的 URL

转载 作者:行者123 更新时间:2023-12-02 08:03:30 24 4
gpt4 key购买 nike

Possible Duplicate:
Remove .php extension with .htaccess

我想将我的所有网站 URL 设置为 myurl/webpageexamples.php ,将重命名为其非扩展版本 myurl/webpageexamples ,如果可能的话 .htaccess同时重定向来自 myurl/webpageexamples.php 的所有流量到新的myurl/webpageexamples .

我发现有几个可以从 PHP 重定向到非 PHP,例如:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]

我有:

myurl/webpageexamples.php

我想要什么:

myurl/webpageexamples

我希望将 SEO 分数转移到新的 myurl/webpageexamples .

最佳答案

如果实际请求是针对 php 页面,您需要确保进行重定向,并在 URI 缺少 php 时进行内部重写:

RewriteEngine On

# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]

关于.htaccess - 将 .php URL 重定向到不带扩展名的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13222850/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com