Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.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
Apache 301重定向正在添加?页=_Apache_.htaccess_Redirect - Fatal编程技术网

Apache 301重定向正在添加?页=

Apache 301重定向正在添加?页=,apache,.htaccess,redirect,Apache,.htaccess,Redirect,我在.htaccess文件中设置了一些301重定向。。。对于不存在的文件。它们确实在重定向,但添加了一个查询。例如: 在我的htaccess文件上使用我的重定向之一,如下所示: 如果我输入example.com/about-example.php,它应该将我重定向到example.com/about-example.html,但它会将我带到example.com/about-example.html?page=about-example.php,并添加?page=(重定向),moz会看到重定向页

我在.htaccess文件中设置了一些301重定向。。。对于不存在的文件。它们确实在重定向,但添加了一个查询。例如:

在我的htaccess文件上使用我的重定向之一,如下所示: 如果我输入example.com/about-example.php,它应该将我重定向到example.com/about-example.html,但它会将我带到example.com/about-example.html?page=about-example.php,并添加?page=(重定向),moz会看到重定向页面的末尾带有一个查询,作为原始页面的副本

以下是我的htaccess的外观。。。(将大量更改为示例/xyz)

选项-索引+FollowSymLinks
重新启动发动机
重写基/
#删除“www”
重写条件%{HTTP_HOST}^www\.(.*)$[NC]
重写规则^(.*)$http://%1/$1[R=301,L]
#将对html文件的任何请求重定向到索引
重写规则^(+)\.html index.php?页面=$1[L]
#重写对要索引的子目录的任何请求
重写cond%{REQUEST_FILENAME}-F
重写规则^(+)$index.php?页面=$1[L,QSA]
##网站推荐禁止
RewriteCond%{HTTP\u REFERER}^HTTP://([^.]+\)*示例\.net/[NC,或]
##过期缓存##
#大多数静态资产为6个月
标题集缓存控制“最大年龄=1576800,公共”
#大多数静态资产为1个月
标题集缓存控制“最大年龄=2628000,公共”
过期于
ExpiresDefault“访问加1个月”
#CSS
ExpiresByType文本/css“访问加1年”
#数据交换
ExpiresByType应用程序/json“访问加0秒”
ExpiresByType应用程序/xml“访问加0秒”
ExpiresByType text/xml“访问加0秒”
#Favicon(无法重命名!)
ExpiresByType图像/x图标“访问加1周”
#HTML组件(HTC)
ExpiresByType文本/x组件“访问加1个月”
#HTML
ExpiresByType text/html“访问加0秒”
#JavaScript
ExpiresByType应用程序/javascript“访问加1年”
#清单文件
ExpiresByType应用程序/x-web-app-manifest+json“访问加0秒”
ExpiresByType文本/缓存清单“访问加0秒”
#媒体
ExpiresByType音频/ogg“访问加1个月”
ExpiresByType image/gif“访问加1个月”
过期按类型图像/jpeg“访问加1个月”
ExpiresByType图像/png“访问加1个月”
按类型视频/mp4“访问加1个月”过期
按类型视频/ogg“访问加1个月”过期
过期按类型视频/webm“访问加1个月”
#网络源
ExpiresByType应用程序/atom+xml“访问加1小时”
ExpiresByType应用程序/rss+xml“访问加1小时”
#网页字体
ExpiresByType应用程序/font-woff2“访问加1个月”
过期按类型应用程序/font woff“访问加1个月”
ExpiresByType应用程序/vnd.ms-fontobject“访问加1个月”
按类型应用程序到期/x-font-ttf“访问加1个月”
ExpiresByType字体/opentype“访问加1个月”
ExpiresByType图像/svg+xml“访问加1个月”
重定向301/about-example.phphttp://example.com/about-example.html
重定向301/vacation-faq.phphttp://example.com/faqs.html
重定向301/3d-tour.htmlhttp://example.com/plans.html
重定向301/images/cool/04.jpghttp://example.com/gallery.html

我是否丢失了一个命令,或者重定向是否位于错误的位置?我试过重写规则,重新定向匹配。。。还有一堆其他的东西,要么是相同的结果,要么是500个内部错误。。(编辑)我还弄乱了重定向的位置,但没有用。

您需要更新规则并在末尾添加一个
。试试这些规则吧

Options -MultiViews
RewriteEngine on
#if request is a real file or dir do nothing
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

#else do these redirects
RewriteRule ^about-example\.php http://example.com/about-example.html? [R=301,L]
RewriteRule ^vacation-faq\.php http://example.com/faqs.html? [R=301,L]
RewriteRule ^3d-tour\.html http://example.com/plans.html? [R=301,L]
RewriteRule ^images/cool/04\.jpg http://example.com/gallery.html? [R=301,L]

让我知道这个答案对你是如何起作用的

您需要更新规则,并在末尾添加一个
。试试这些规则吧

Options -MultiViews
RewriteEngine on
#if request is a real file or dir do nothing
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

#else do these redirects
RewriteRule ^about-example\.php http://example.com/about-example.html? [R=301,L]
RewriteRule ^vacation-faq\.php http://example.com/faqs.html? [R=301,L]
RewriteRule ^3d-tour\.html http://example.com/plans.html? [R=301,L]
RewriteRule ^images/cool/04\.jpg http://example.com/gallery.html? [R=301,L]

让我知道这个答案对你是如何起作用的

我不完全理解你的问题,但你有一个具体的重写来做这件事
RewriteRule^(+)\.html index.php?page=$1[L]
我会编辑我的主要评论来进一步解释。我不完全理解你的问题,但你有一个具体的重写来做这件事
RewriteRule^(+)\.html index.php?page=$1[L]
我将编辑我的主要评论以作进一步解释。您好,谢谢您的帮助。所以我用一个测试了它,它确实重定向到一个页面,但是现在它有一个?在URL的末尾。这应该会发生吗?还有,这是什么?真的吗?@dhath在这里尝试使用重写。我修改了4条规则。
告诉它删除任何查询字符串,如果它在请求中,就不要追加它。我使用了rewrite,它只是转到404页面。RedirectMatch 301可以工作,只是想知道页面末尾的“?”是否算作不同的页面,从而导致重复的内容<代码>重写规则^contact\.phphttp://example.com/contact-example.html? [R=301,L]就是我说的。我的意思是?在URL的末尾不是页面。页面是否重定向到真实页面?您好,谢谢您的帮助。所以我用一个测试了它,它确实重定向到一个页面,但是现在它有一个?在URL的末尾。这应该会发生吗?还有,这是什么?真的吗?@dhath在这里尝试使用重写。我修改了4条规则。
告诉它删除任何查询字符串,如果它在请求中,就不要追加它。我使用了rewrite,它只是转到404页面。RedirectMatch 301可以工作,只是想知道页面末尾的“?”是否算作不同的页面,从而导致重复的内容<代码>重写规则^contact\.phphttp://example.com/contact-example.html? [R=301,L]是我想要的