如何在.htaccess中重定向无效的URL?

时间:2013-11-19 10:58:10

标签: apache .htaccess symfony-1.4

/ (directory/?param=value)无法更改此网址

directory/?param=value

directory/value

这不起作用:

RewriteCond   %{REQUEST_URI} ^/directory/.*

RewriteRule   ^/directory/\?param=(.*)    /directory/$1 [L]

我的问题是如何替换?param = ???

2 个答案:

答案 0 :(得分:0)

这些规则适合您:

RewriteEngine On

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

RewriteRule ^(directory)/([^/]+)/?$ /$1/?param=$2 [L,QSA,NC]

答案 1 :(得分:0)

您无法与?中的查询字符串(RewriteRule之后的所有内容)匹配,请尝试:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?directory/(.+)$ /directory/?param=$1 [L]

这需要:目录/值并在内部重写以提供目录/?param = value 中的内容。