重定向的.php的URL网址不带扩展名 [英] Redirect .php urls to urls without extension

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

问题描述

可能重复:
  删除扩展名为.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]

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

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