问题
I have a problem with htaccess redirecting a variable to clean url.
the code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?page=$1 [R]
RewriteCond %{QUERY_STRING} ^page=about$
RewriteRule ^(.*)$ https://www.url.com/about? [R=301,L]
i just want to redirect this: "?page=about" to this: "/about"
and with the code above give me to many redirects...
Thanks for the time to look at this.
回答1:
So i have tried your code in an empty directory on local server.
This works fine:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?page=$1 [R]
RewriteCond %{QUERY_STRING} ^page=about$
RewriteRule ^(.*)$ https://www.url.com/about? [R=301,L]
</IfModule>
But not when i comment out this line of code RewriteEngine on
. So try your code with this piece of line and it should work fine.
回答2:
Thats the complete code.
#Rewrite settings
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^url.com [NC]
RewriteRule ^(.*)$ https://www.url.com/$1 [L,R=301]
#Remove index.php from url
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php?p=$1 [L]
#RewriteCond %{QUERY_STRING} ^p=about$
#RewriteRule ^(.*)$ https://www.url.com/about? [R=301,L]
RewriteCond %{HTTP_USER_AGENT} libwww-perl.*
RewriteRule .* ? [F,L]
This piece of code is commented because like this does not work:
#RewriteCond %{QUERY_STRING} ^p=about$
#RewriteRule ^(.*)$ https://www.url.com/about? [R=301,L]
来源:https://stackoverflow.com/questions/44567637/htaccess-redirect-variable-to-friendly-link-many-redirects