将所有带“videos.php”的网址重定向到基地

时间:2013-04-03 18:47:53

标签: .htaccess mod-rewrite

我希望有人可以帮助我使用mod_rewrite规则重定向动态网址,指向" videos.php"在我的服务器上到基本网址。

例如,我需要重定向' website.com/1/music/various/videos.php?= 1234' 到' website.com/videos.php?= 1234'

编辑:我正在寻找动态解决方案。如果一个url随时指向videos.php,我需要进行301重定向到主目录。即如果/1/home/music/videos.php?=1234重定向到/videos.php?=1234,或/music/playlist/1234/videos.php?1432到/videos.php?1432。

2 个答案:

答案 0 :(得分:1)

创建.htaccess文件并插入以下行:

RewriteEngine On

# Page moved permanently:
RewriteRule ^videos\.php\?\=([0-9]+)\.html$ /1/music/various/videos.php?=$1 [R=301,L]

进行测试时,请忽略R=301,部分,否则您只会长时间看到缓存内容。在确定其正常工作时添加它。或者使用302,这意味着暂时。

答案 1 :(得分:0)

请检查:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_URI} ^/1/music/various/videos.php$
RewriteCond %{QUERY_STRING} (.+)$
RewriteRule ^(.*) /videos.php [R,QSA]

RewriteCond %{REQUEST_URI} ^/videos.php$
RewriteCond %{QUERY_STRING} !(.+)$
RewriteRule ^(.*) http://%{HTTP_HOST}/ [R=301]

如果它不起作用,那么试试这个:

Options +FollowSymlinks
RewriteEngine on

RewriteCond %{REQUEST_URI} ^/1/music/various/videos.php$
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^(.*) /videos.php%1 [R]

RewriteCond %{REQUEST_URI} ^/videos.php$
RewriteCond %{QUERY_STRING} !(.+)$
RewriteRule ^(.*) http://%{HTTP_HOST}/ [R=301]