作者:淡定神仙2502891317 | 来源:互联网 | 2023-05-19 05:11
Ivegotasitewhereallthepagesarephpscripts,sotheURLsend.php.我有一个网站,所有的页面都是php脚本,url以。
I've got a site where all the pages are php scripts, so the URLs end .php.
我有一个网站,所有的页面都是php脚本,url以。php结尾。
I've added the following to a .htaccess file, and I can now access the .php files without the .php extension:
我在.htaccess文件中添加了以下内容,现在可以不使用.php扩展名访问.php文件:
RewriteEngine On # Turn on rewriting
RewriteCond %{REQUEST_FILENAME}.php -f # If the requested file with .php on the end exists
RewriteRule ^(.*)$ $1.php # serve the PHP file
So far so good. But now I want to add a Redirect on all the .php files so that any old links outside of my control get redirected to the new version of the URL.
目前为止一切都很顺利。但是现在我想在所有。php文件上添加一个重定向,以便在我的控件之外的任何旧链接都被重定向到URL的新版本。
I've tried this:
我已经试过这个:
RewriteEngine On # Turn on rewriting
RewriteCond %{REQUEST_URI} .*\.php
RewriteRule ^(.*)\.php$ http://example.com/$1 [R=permanent,L]
RewriteCond %{REQUEST_FILENAME}.php -f # If the requested file with .php on the end exists
RewriteRule ^(.*)$ $1.php [L] # serve the PHP file
but that seems to send a redirect even for URLs that don't end in .php, so I get stuck in an infinite loop. Any other combination I try seems to match no requests (and leave me at page.php) or all requests (and get me stuck in a loop).
但这似乎发送了一个重定向,即使url以。php结尾,所以我陷入了无限循环。我尝试的任何其他组合似乎都不匹配任何请求(并将我留在page.php)或所有请求(使我陷入循环)。
5 个解决方案