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 使用.htaccess将查询字符串追加到URL_Apache_.htaccess_Mod Rewrite_Http Redirect - Fatal编程技术网

Apache 使用.htaccess将查询字符串追加到URL

Apache 使用.htaccess将查询字符串追加到URL,apache,.htaccess,mod-rewrite,http-redirect,Apache,.htaccess,Mod Rewrite,Http Redirect,我需要做这样的事情:URL应该重新定向到我该怎么做?提前感谢。很少有人想将不利于搜索引擎优化的URL重定向到不利于搜索引擎优化的URL,通常是另一种方式,因此请确保您想要: http://domain.com/view.php?show=xyz => http://domain.com/xyz/ 而不是更常见的: http://domain.com/xyz => http://domain.com/view.php?show=xyz 您

我需要做这样的事情:URL应该重新定向到我该怎么做?提前感谢。

很少有人想将不利于搜索引擎优化的URL重定向到不利于搜索引擎优化的URL,通常是另一种方式,因此请确保您想要:

http://domain.com/view.php?show=xyz   =>   http://domain.com/xyz/
而不是更常见的:

http://domain.com/xyz                 =>   http://domain.com/view.php?show=xyz
您可以使用类似的方法捕获查询字符串并将其传递到URL(我已将
R=301
添加到标志中,但如果不希望永久重定向,请将其替换为
R
):

未经测试,因为我目前没有运行Apache,但如果它有帮助但不正确,请给我工作代码以修复我的答案。

您可以尝试以下规则:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+view\.php\?show=([^\s]+) [NC]
RewriteRule ^ /%1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ /view.php?show=$1 [L,QSA,NC]

确认其工作正常后,将
R=302
更换为
R=301
。在测试mod_重写规则时,避免使用
R=301
(永久重定向)。

嗨,在堆栈溢出和更广泛的Internet上,有一百万个资源用于此。请始终先搜索。谢谢不幸的是,我只找到了这个版本,但它不适合我:
RewriteRule^blog/([-a-zA-Z0-9+)/?view.php?&show=$1[L]
,即重定向到,不幸的是,它对我不起作用。我得到了404。检查access.log和error.log,Apache问题通常很容易调试。@RedOctober-Edited,告诉我这是否解决了它。注意:在测试时,您可能希望使用
R
而不是
R=301
,因为某些浏览器会长时间缓存301s。我仍然有404:(在
access.log
error.log
中有什么内容?您需要为我提供更多信息以进一步帮助我,因为我这里没有运行Apache。谢谢,它对我有用!不客气,很高兴它成功了。
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+view\.php\?show=([^\s]+) [NC]
RewriteRule ^ /%1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ /view.php?show=$1 [L,QSA,NC]