问题
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