why does my rewrite rule without redirect give a 500 error?

做~自己de王妃 提交于 2019-12-13 00:49:24

问题


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>

回答1:


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.



来源:https://stackoverflow.com/questions/19316478/why-does-my-rewrite-rule-without-redirect-give-a-500-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!