获取价值并使用htaccess重定向

时间:2014-04-11 03:03:53

标签: php regex apache .htaccess mod-rewrite

我想将http://example.com/search/search.php?q=videos重定向到http://example.com/search/videos

我试图这样做,但它不起作用。这里是我的htaccess文件:http://example.com/search/.htaccess

<Files .htaccess>
order allow,deny
</Files>

Options +FollowSymLinks
RewriteEngine On
RewriteBase /search/

RewriteRule ^([^/]+)(?:/[^/]+)?/?$ search.php?q=$1 [L,QSA]

RewriteRule ^([^/]+)/[^/]+/([0-9]+)/?$ search.php?q=$1&p=$2 [L,QSA]

RewriteRule ^search/(.*)$ load.php?q=$1 [L]

上一个RewriteRule无法正常工作..如何修复..帮助...谢谢RewriteRule ^search/(.*)$ load.php?q=$1 [L]

1 个答案:

答案 0 :(得分:1)

/search/.htaccess

中使用此代码
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /search/

RewriteCond %{THE_REQUEST} /search\.php\?q=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/?$ search.php?q=$1 [L,QSA]

RewriteRule ^[^/]+/([0-9]+)/?$ search.php?q=$1&p=$2 [L,QSA]