使用的.htaccess方法删除PHP扩展(保持链接汁) [英] Remove PHP extension using .htaccess methods (Keeping Link Juice)
问题描述
我试图删除PHP扩展在我的网址,使之使用.htaccess文件重定向301,以保持等级果汁搜索引擎友好的和我一样多我已经试过周围几乎每一个例子 - 它只是似乎没有工作。
I'm trying to remove the .php extension on my URLs to make it Search Engine Friendly using the .htaccess file Redirect 301, to keep the "rank juice" and I as much I've tried almost every example around - It just doesn't seem to work.
下面是一些我已经试过失败早已方法:
Here are some of the methods I've unsuccessfully tried already:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
这是给定的最常见的解决方案,但没有任何反应,并且没有改变。的
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /$1.php [L]
没有任何反应,也没有改变。的
RewriteEngine On
# RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
# RewriteRule (.*)\.php$ /$1 [L,R=301]
# RewriteRule (.*)/$ $1.php [L]
我得到的未找到:请求的URL /AMENPTHOME/hostnd/3/9/9/399fc7b78/www/htdocs/web/dive-sites.php没有被发现此服务器。的
I get a Not Found : The requested URL /AMENPTHOME/hostnd/3/9/9/399fc7b78/www/htdocs/web/dive-sites.php was not found on this server.
阿门是我的主机和文件潜水sites.php在这个具体实际的例子是根。 我的目标是有: www.domain.com/dive-sites 而非 www.domain.com/dive-sites.php 使用重定向301,因为这个网址是已经排了一会儿。是否有人可以帮忙吗?
Amen is my host and the file dive-sites.php in this specific real example is on the root. My goal is to have: www.domain.com/dive-sites and not www.domain.com/dive-sites.php using a Redirect 301 because this url is already ranked for a while. Can someone please help ?
非常感谢你,都有助于AP preciated。
Thank you very much, all help appreciated.
推荐答案
如果我没有错过什么:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/(.+)\.php[^\s]* [NC]
RewriteRule ^ /%1 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [QSA,NC,L]
要求为 /dive-sites.php
将发行301重定向到 /潜水点
,追加查询-strings如果有的话。
Requests to /dive-sites.php
will issue a 301 redirect to /dive-sites
, appending query-strings if any.
要求为 /潜水点
将得到一个200响应与 /dive-sites.php
为内容位置
,追加查询字符串,如果有的话。
Requests to /dive-sites
will get a 200 response with /dive-sites.php
as Content-Location
, appending query-strings if any.
这篇关于使用的.htaccess方法删除PHP扩展(保持链接汁)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!