重定向的.php的URL网址不带扩展名扩展名、不带、重定向、网址

2023-09-02 20:34:23 作者:残雾

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

我要让我所有的网站的url myurl / webpageexamples.php重命名为它的非扩展版本myurl / webpageexamples - 如果可能的htaccess-,并在同一时间重定向所有流量从myurl / webpageexamples.php到新myurl / webpageexamples。

I want to make all my website url 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

What I have: myurl/webpageexamples.php

我想: myurl / webpageexamples 有搜索引擎优化得分转移到新的myurl / webpageexamples

What I want: myurl/webpageexamples having 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]