首页 文章

PHP中的URL重定向

提问于
浏览
1

我有一个像http://localhost/joomla/Joomla_1.5.7/index.php?option=com_content&view=section&layout=blog&id=3&Itemid=55的网址

我想将其重定向到http://localhost/joomla/Joomla1.5/index.php?option=com_content&view=section&layout=blog&id=3&Itemid=55

不仅这个重定向,但每当我有任何东西旁边Joomla_1.5.7 /我试图将其附加到Joomla1.5 ..如何在PHP中执行此操作....如何识别该URL在Joomla_1.5.7之后包含的内容得到它??

编辑:##如果导致错误可以注释掉,请参阅上面的注释 . 选项FollowSymLinks

#
  #  mod_rewrite in use

  RewriteEngine On

########## Begin - Rewrite rules to block out some common exploits
   ## If you experience problems on your site block out the operations listed below
   ## This attempts to block the most common type of exploit `attempts` to Joomla!
   #
   # Block out any script trying to set a mosConfig value through the URL
   RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
    # Block out any script trying to base64_encode crap to send via URL
  RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
  # Block out any script that includes a <script> tag in URL
 RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
 # Block out any script trying to set a PHP GLOBALS variable via URL
 RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})

#发送所有被阻止的请求到主页403 Forbidden错误! RewriteRule ^( . *)$ index.php [F,L] ########### End - 重写规则以阻止一些常见的漏洞利用

#  Uncomment following line if your webserver's URL
#  is not directly related to physical file paths.
#  Update Your Joomla! Directory (just / for root)

# RewriteBase /


  ########## Begin - Joomla! core SEF Section

#RewriteCond%!-f RewriteCond%!-d RewriteCond%!^ / index.php RewriteCond%(/| .php|.html | .htm | .feed | .pdf | .raw | /[^.])$ [NC] RewriteRule( . )index.php RewriteRule . * - [E = HTTP_AUTHORIZATION:%{HTTP:Authorization},L] ###########结束 - Joomla!核心SEF科

RewriteEngine on
 RewriteCond %{REQUEST_URI} ^/joomla/Joomla_1\.5\.7/.*
 RewriteRule ^(.*)$ http://%{HTTP_HOST}/joomla/Joomla1.5/$1 [R=301,L]

是我的htaccess文件中的内容,但它仍显示我的网站中的任何更改 .

2 回答

  • 4

    您可以使用这样的htaccess文件执行此操作:

    RewriteEngine on
    RewriteRule ^joomla/Joomla_1.5.7/(.*?)$ joomla/Joomla1.5/$1 [L,QSA]
    

    但是如果你绝对想用PHP实现它,那就把它放在旧的index.php中:

    header("Status: 301");
    header("Location: http://localhost/joomla/Joomla1.5/index.php".(!empty($_GET) ? '?'.http_build_query($_GET) : ''));
    exit;
    
  • 0

    如果你有mod_rewrite,在.htaccess中你可以放一些东西:

    RewriteEngine on
    
    RewriteCond %{REQUEST_URI} ^/joomla/Joomla_1\.5\.7/.*
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/joomla/Joomla1.5/$1 [L]
    

    基本上,它匹配以/joomla/Joomla_1.5.7/开头的任何传入URL,并将其重定向到/joomla/Joomla1.5/,所有额外参数都保持不变,但URL不会在用户的地址栏中更改 .

    如果要更改URL,可以将最后一行更改为

    RewriteRule ^(.*)$ http://%{HTTP_HOST}/joomla/Joomla1.5/$1 [R=301,L]
    

    希望这是你正在寻找的!

相关问题