Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess htaccess使用重定向循环重新写入URL_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

.htaccess htaccess使用重定向循环重新写入URL

.htaccess htaccess使用重定向循环重新写入URL,.htaccess,mod-rewrite,redirect,.htaccess,Mod Rewrite,Redirect,我有一个与php在URL索引现有的网站。我想将URL更改为不包含PHP,以便将page.PHP重写为 重写正在进行,但重定向会在我尝试使用page.php访问页面时导致“页面无法在循环中显示”错误 我需要弄清楚如何设置重定向并重写URL,因为Google现在已经为PHP URL和漂亮的URL编制了索引 我在网上看了无数页,但找不到答案 请帮忙 这是我的访问权限 # The redirect below caused a loop when I access the page as # http

我有一个与php在URL索引现有的网站。我想将URL更改为不包含PHP,以便将page.PHP重写为

重写正在进行,但重定向会在我尝试使用page.php访问页面时导致“页面无法在循环中显示”错误

我需要弄清楚如何设置重定向并重写URL,因为Google现在已经为PHP URL和漂亮的URL编制了索引

我在网上看了无数页,但找不到答案

请帮忙

这是我的访问权限

# The redirect below caused a loop when I access the page as 
# http://example.com/thepage.php
# Moving the redirect after the rewrite didn't work either. 

Redirect 301 /thepage.php http://example.com/thepage

RewriteEngine on
# Rewrite works. The page does display corectly for this link
#    http://example.com/thepage

<IfModule mod_rewrite.c> 
   Options +FollowSymLinks 
   Options +Indexes 
 #  RewriteEngine On 
   RewriteCond %{SCRIPT_FILENAME} !-d 
#RewriteRule ^photos([^\.]+)$ photos [NC,L]
   RewriteRule ^([^\.]+)$ $1.php [NC,L] 
</IfModule>


ErrorDocument 404 http://example.com/

谢谢你

你的重写规则与它的发音相反

这里我们捕获所有不包含句点的php文件,并将它们重定向到一个只使用名称而不使用扩展名的目录URI。[R=301]是一个永久的301重定向,它告诉任何人页面已不在原来的位置

RewriteEngine on
RewriteRule ^([^\.]+).php$ $1 [NC,L,R=301] 
您可能只想在不使用301的情况下使用R测试这些,以确保其正常工作。如果301重定向不起作用,它将缓存在最终用户的浏览器缓存中,直到过期


Apache有一个解决方案。

我终于能够回到这个问题并找到解决方案。我希望这能帮助别人。我在这个问题上大发雷霆

我找到了很多例子,但没有找到我需要的组合

#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301,NC]

RewriteBase /

# hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+).php [NC]
RewriteRule ^ %1 [R,L,NC]

# To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

ErrorDocument 404 http://example.com/

非常感谢。当我这样做时,除了在选项+FollowSymLinks选项+索引RewriteCond%{SCRIPT_FILENAME}上的主页重写引擎之外,所有页面都会出现404错误-重写规则^[^\.]+.php$$1[NC,L,R=301]错误文档404