So have rewritten my ugly php URL to something prettier:
所以我把丑陋的php URL重写为更漂亮的东西:
RewriteEngine On
RewriteRule ^main/photo([^/\.]+)/?.html$ main/details.php?gid=$2pid=$1
However, now I want to force anyone who goes to
但是,现在我想强迫任何人去
http://www.example.com/main/details.php?gid=20&pid=5
to redirect to
重定向到
htto://www.example.com/main/photo5.html
I have tried the following RewriteCond:
我尝试过以下RewriteCond:
RewriteCond %{REQUEST_URI} ^/main/details\.php [NC]
RewriteRule ^main/details.php?gid=(.*)&pid=(.*) http://www.example.com/main/photo$1.html [R=301,L]
But that didn't work. Any ideas?
但那没用。有任何想法吗?
1 个解决方案
#1
You need to look into the request line to determine if the current request URI is the original. Additionally you need to use the RewriteCond
directive to test the query of the URI:
您需要查看请求行以确定当前请求URI是否是原始URI。此外,您需要使用RewriteCond指令来测试URI的查询:
RewriteCond %{THE_REQUEST} ^GET\ /main/details\.php
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)pid=([0-9]+)(&.*)?$
RewriteRule ^main/details\.php$ /main/photo%3.html? [L,R=301]
#1
You need to look into the request line to determine if the current request URI is the original. Additionally you need to use the RewriteCond
directive to test the query of the URI:
您需要查看请求行以确定当前请求URI是否是原始URI。此外,您需要使用RewriteCond指令来测试URI的查询:
RewriteCond %{THE_REQUEST} ^GET\ /main/details\.php
RewriteCond %{QUERY_STRING} ^(([^&]*&)*)pid=([0-9]+)(&.*)?$
RewriteRule ^main/details\.php$ /main/photo%3.html? [L,R=301]