【问题标题】:Re-write links only not redirect仅重写链接不重定向
【发布时间】:2013-05-02 22:58:14
【问题描述】:

您好,我对 htaccess 了解不多,也无法理解代码的工作原理。

谁能帮我做这个

www.site.com/forums/index.php?/cp/3-welcome/

只会将文本本身更改为

www.site.com/forums/welcome

不重定向它。

【问题讨论】:

  • RewriteCond %{REQUEST_URI} ^/forums/index.php$ RewriteCond %{QUERY_STRING} ^/cp/6-monthly-member-profile RewriteRule ^(.*)$ site.org/forums/monthly-member-profile? [R=302,L] 试过了,但它重定向了我,因此给了我一个 404 页面

标签: html


【解决方案1】:

您首先要确保启用了重写规则。您可以通过 .htaccess 文件使用类似于以下的代码来执行此操作:

<Directory /var/www/website/html>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/images/
    RewriteRule ... ...
    RewriteRule 
</Directory>

完成后,您应该能够运行 RewriteCond 命令,以便在启用重写引擎时成功重定向。

.htaccess 文件中的重定向应该类似于:

RewriteRule ^http://([^/]*)/forums/welcome(\d+)/(.*)$ 
http://$1/index.php?/cp/3-welcome/

当然,您可能需要根据您的特定需求对其进行更新/编辑,但这至少应该让您大致了解一下。

【讨论】:

  • 介意我如何实际编写代码? www.site.com/forums/index.php?/cp/3-welcome/ 到 www.site.com/forums/welcome
  • 因为我真的不知道该怎么做。
  • 您的网站是手动构建的,还是通过应用程序(例如 WordPress/Joomla/Drupal)或类似的东西构建的?
  • 使用 Invision 构建。但应用程序位于 public_html/forums
猜你喜欢
  • 2017-07-10
  • 1970-01-01
  • 1970-01-01
  • 2019-08-03
  • 2018-07-23
  • 2013-04-03
  • 1970-01-01
  • 1970-01-01
  • 2011-08-24
相关资源
最近更新 更多