info with mod_rewrite.htaccess

问题描述 投票:0回答:2

我一直在尝试从我的网站上摆脱.php。我希望它看起来像example.com/about,而不是example.com/about.php。我有它会重写它,以便我可以将其输入示例: .com/about而不是example.com/about.php。总的来说,我想要它,以便每当有人在我的页面上加载任何东西时,URL的末尾都没有.php。我的.htaccess现在看起来像是如此,

RewriteEngine on

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php

谢谢你

.htaccess optimization mod-rewrite
2个回答
1
投票
但我希望它是在我单击网站上的链接以访问xpessup.com/about时加载URL作为example.com/about,而不是example.com/about.com/about.php

要解决这个问题,您需要将网站从

example.com/about.php

更改为
example.com/about
。当链接“在野外”仍然指向
.php
URL时,您仍然可以重定向,但是除非您更改网站上的链接以删除扩展名,否则您的每个页面都会导致每个页面加载两次。

为重定向:

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

我不确定您的规则如何使PHP扩展退回起来,因为您要匹配尾随的斜线,但是当您使用
-f

检查文件时,您会在文件名中有一个流浪的拖拉斜线:例如

/some/path/to/the_file/.php
而不是
/some/path/to/the_file.php
try:

RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} ^/(.+?)/? RewriteCond %{DOCUMENT_ROOT}/%1.php -f RewriteRule ^ /%1.php [L]

trone this:

1
投票
您不必更改网站的结构,因为它只是以

http://example.com/page

的形式靶向“畸形” URI,而无需延长。希望我帮忙!
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.