为什么我没有重定向重写规则给出一个500错误? [英] why does my rewrite rule without redirect give a 500 error?

查看:802
本文介绍了为什么我没有重定向重写规则给出一个500错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重写URL像

  mysite.com/eng?sentence=cat
 

显示,如:

  mysite.com/eng/cat
 

我不想重定向只是重写。所以我尝试改变重写规则我才发现,这个例子在我编辑它有一个R = 301在它原来:

 的RewriteCond%{THE_REQUEST} ^ GET \ / ENG \句子=([^&放大器; \ S] +)[NC]
重写规则^ ENG \?一句话= $ /英文/%1? [R = 302,NC,L]
 

但是当我从第2行中删除R = 301,它提供了500错误。

我怎么能写这样的重写规则呢?我不是伟大与此正则表达式的东西,我也不是熟悉

我的htaccess文件:

 #使用PHP5.3单php.ini中的默认
AddHandler的应用程序/ x-的httpd-php54s的.php
将AddType应用/ X的httpd  -  PHP的.htm的.html

选项​​-Indexes -MultiViews

ErrorDocument的404 /404.php
ErrorDocument的500 /500.php

RewriteEngine叙述上

?的RewriteCond%{THE_REQUEST} ^ GET \ / ENG \句子=([^&放大器; \ S] +)[NC]
重写规则^ ENG \?一句话= $ /英文/%1? [R = 302,NC,L]



的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_FILENAME} \ PHP -f
重写规则^(。*)$ $ 1.PHP [L]

< FilesMatch&GT\(JPG | JPEG | PNG | | GIF SWF)$。;
    页眉设置缓存控制最大年龄= 604800,公开
< / FilesMatch>
 

解决方案

使用行结束标记 $ 或者在的RewriteCond

 的RewriteCond%{THE_REQUEST} ^ GET \ S / ENG \句子=([^&放大器; \ S] +)[NC]
重写规则^ / ENG /%1? [NC,L,R = 302]
 

最有可能500是因为由于你的.htaccess其他规则循环的。我建议你​​张贴满的.htaccess code在你的问题。

i want to rewrite urls like

mysite.com/eng?sentence=cat

to show like:

mysite.com/eng/cat

I dont want a redirect just a rewrite. so I tried altering a rewrite rule i found, the example before i edited it had a R=301 in it originally:

RewriteCond %{THE_REQUEST} ^GET\ /eng\?sentence=([^&\s]+) [NC]
RewriteRule ^eng\?sentence=$ /english/%1? [R=302,NC,L]

but when i remove the R=301 from the 2nd line it gives a 500 error.

how can I write this kind of rewrite rule? Im not great with this regex stuff, nor am i familiar with this

my htaccess file:

# Use PHP5.3 Single php.ini as default
AddHandler application/x-httpd-php54s .php
AddType application/x-httpd-php .htm .html

Options -Indexes -MultiViews

ErrorDocument 404 /404.php
ErrorDocument 500 /500.php

RewriteEngine on

RewriteCond %{THE_REQUEST} ^GET\ /eng\?sentence=([^&\s]+) [NC]
RewriteRule ^eng\?sentence=$ /english/%1? [R=302,NC,L]



RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=604800, public"
</FilesMatch>

解决方案

Use line end anchor $ OR else just reply on RewriteCond

RewriteCond %{THE_REQUEST} ^GET\s/eng\?sentence=([^&\s]+) [NC]
RewriteRule ^ /eng/%1? [NC,L,R=302]

Most likely 500 is because of looping due to other rules in your .htaccess. I suggest you posting full .htaccess code in your question.

这篇关于为什么我没有重定向重写规则给出一个500错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆