将 .php URL 重定向到没有扩展名的 URL [英] Redirect .php URLs to URLs without extension

查看:29
本文介绍了将 .php URL 重定向到没有扩展名的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
使用 .htaccess 删除 .php 扩展名

如果可能,我想将我的所有网站 URL myurl/webpageexamples.php 重命名为其非扩展版本 myurl/webpageexampleshref="https://en.wikipedia.org/wiki/.htaccess" rel="nofollow noreferrer">.htaccess 并同时重定向来自 myurl/webpageexamples.php 到新的 myurl/webpageexamples.

I want to make all my website URLs, myurl/webpageexamples.php, to be renamed to its non-extension version myurl/webpageexamples, if possible in .htaccess and at the same time redirect all traffic from myurl/webpageexamples.php to the new myurl/webpageexamples.

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

I have found several to redirect from PHP to non-PHP like:

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

我有什么:

myurl/webpageexamples.php

我想要的:

myurl/webpageexamples

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

I would like to have the SEO score transferred to new myurl/webpageexamples.

推荐答案

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

You want to make sure you are redirecting if the actual request is for a php page, and internally rewriting when the URI is missing the 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]

这篇关于将 .php URL 重定向到没有扩展名的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆