Php .htaccess重定向javascript资源

Php .htaccess重定向javascript资源,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,我已经将我网站的论坛移到了一个子文件夹中,但是有一些资源URL不再工作了,我想做如下重定向,从 mydomain.com/jscripts/popup_menu.js?ver=1600 到 在.htaccess中,我放置了以下内容: RewriteRule ^/jscripts/$ /forum/$1 [R=301,L] 似乎不对,正确的形式是什么?谢谢 全部内容: # # Apache/PHP/Drupal settings: # # Protect files and director

我已经将我网站的论坛移到了一个子文件夹中,但是有一些资源URL不再工作了,我想做如下重定向,从

mydomain.com/jscripts/popup_menu.js?ver=1600

在.htaccess中,我放置了以下内容:

RewriteRule ^/jscripts/$ /forum/$1 [R=301,L]
似乎不对,正确的形式是什么?谢谢

全部内容:

#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
  Order allow,deny
</FilesMatch>

# Don't show directory listings for URLs which map to a directory.
Options -Indexes

# Follow symbolic links in this directory.
# Options +FollowSymLinks

# Make Drupal handle any 404 errors.
ErrorDocument 404 /index.php

# Force simple error message for requests for non-existent favicon.ico.
<Files favicon.ico>
  # There is no end quote below, for compatibility with Apache 1.3.
  ErrorDocument 404 "The requested file favicon.ico was not found.
</Files>

# Set the default handler.
DirectoryIndex index.php

# Override PHP settings. More in sites/default/settings.php
# but the following cannot be changed at runtime.

# PHP 4, Apache 1.
<IfModule mod_php4.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# PHP 4, Apache 2.
<IfModule sapi_apache2.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# PHP 5, Apache 1 and 2.
<IfModule mod_php5.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
  php_value mbstring.http_input             pass
  php_value mbstring.http_output            pass
  php_value mbstring.encoding_translation   0
</IfModule>

# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
  # Enable expirations.
  ExpiresActive On

  # Cache all files for 2 weeks after access (A).
  ExpiresDefault A1209600

  <FilesMatch \.php$>
    # Do not allow PHP scripts to be cached unless they explicitly send cache
    # headers themselves. Otherwise all scripts would have to overwrite the
    # headers set by mod_expires if they want another caching behavior. This may
    # fail if an error occurs early in the bootstrap process, and it may cause
    # problems if a non-Drupal PHP file is installed in a subdirectory.
    ExpiresActive Off
  </FilesMatch>
</IfModule>

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  # If your site can be accessed both with and without the 'www.' prefix, you
  # can use one of the following settings to redirect users to your preferred
  # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  #
  # To redirect all users to access the site WITH the 'www.' prefix,
  # (http://example.com/... will be redirected to http://www.example.com/...)
  # adapt and uncomment the following:
  # RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
  # RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
  #
  # To redirect all users to access the site WITHOUT the 'www.' prefix,
  # (http://www.example.com/... will be redirected to http://example.com/...)
  # uncomment and adapt the following:
  # RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
  # RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

  # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  # VirtualDocumentRoot and the rewrite rules are not working properly.
  # For example if your site is at http://example.com/drupal uncomment and
  # modify the following line:
  # RewriteBase /drupal
  #
  # If your site is running in a VirtualDocumentRoot at http://example.com/,
  # uncomment the following line:
  # RewriteBase /

  # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
  RewriteRule ^/jscripts/(.+)$ /forum/jscripts/$1 [R=301,L]
</IfModule>

# $Id$
#
#Apache/PHP/Drupal设置:
#
#保护文件和目录免受窥探。
命令允许,拒绝
#不显示映射到目录的URL的目录列表。
选项-索引
#遵循此目录中的符号链接。
#选项+FollowSymLinks
#让Drupal处理任何404错误。
ErrorDocument 404/index.php
#对不存在的favicon.ico请求强制发送简单错误消息。
#为了与Apache1.3兼容,下面没有结束语。
ErrorDocument 404“未找到请求的文件favicon.ico。
#设置默认处理程序。
DirectoryIndex.php
#覆盖PHP设置。更多信息,请访问sites/default/settings.PHP
#但在运行时无法更改以下内容。
#PHP4,Apache1。
php\u值魔法\u引号\u gpc 0
php\u值寄存器\u全局0
php_值session.auto_启动0
php_值mbstring.http_输入传递
php_值mbstring.http_输出过程
php_值mbstring.encoding_翻译0
#PHP4,Apache2。
php\u值魔法\u引号\u gpc 0
php\u值寄存器\u全局0
php_值session.auto_启动0
php_值mbstring.http_输入传递
php_值mbstring.http_输出过程
php_值mbstring.encoding_翻译0
#PHP5、Apache1和Apache2。
php\u值魔法\u引号\u gpc 0
php\u值寄存器\u全局0
php_值session.auto_启动0
php_值mbstring.http_输入传递
php_值mbstring.http_输出过程
php_值mbstring.encoding_翻译0
#需要启用mod_expires。
#启用过期。
过期于
#访问后将所有文件缓存2周(A)。
到期默认A1209600
#不允许缓存PHP脚本,除非它们显式地发送缓存
#标题本身。否则所有脚本都必须覆盖
#如果mod_设置的头需要另一个缓存行为,则会过期。这可能会导致
#如果在引导过程的早期出现错误,则失败,并可能导致
#如果在子目录中安装了非Drupal PHP文件,则会出现问题。
过期活动关闭
#各种重写规则。
重新启动发动机
#如果您的站点既可以使用“www.”前缀访问,也可以不使用“www.”前缀访问,则您可以
#可以使用以下设置之一将用户重定向到您的首选
#URL,带或不带“www.”前缀。请仅选择一个选项:
#
#要重定向所有用户以访问带有“www.”前缀的网站,
# (http://example.com/... 将被重定向到http://www.example.com/...)
#调整和取消注释以下内容:
#RewriteCond%{HTTP_HOST}^example\.com$[NC]
#重写规则^(.*)$http://www.example.com/$1[L,R=301]
#
#要重定向所有用户以访问不带“www.”前缀的站点,
# (http://www.example.com/... 将被重定向到http://example.com/...)
#取消注释并调整以下内容:
#RewriteCond%{HTTP_HOST}^www\.example\.com$[NC]
#重写规则^(.*)$http://example.com/$1[L,R=301]
#如果在子目录或子目录中使用Drupal,请修改RewriteBase
#VirtualDocumentRoot和重写规则无法正常工作。
#例如,如果您的站点位于http://example.com/drupal 取消注释和
#修改以下行:
#重写BASE/drupal
#
#如果您的站点在以下位置的VirtualDocumentRoot中运行:http://example.com/,
#取消对以下行的注释:
#重写基/
#将表单“x”的URL重写为表单“index.php?q=x”。
重写cond%{REQUEST_FILENAME}!-f
重写cond%{REQUEST_FILENAME}!-d
RewriteCond%{REQUEST_URI}!=/favicon.ico
重写规则^(.*)$index.php?q=$1[L,QSA]
重写规则^/jscript/(.+)$/forum/jscript/$1[R=301,L]
#$Id$

我认为这是您想要的重写规则:

RewriteRule ^/jscripts/(.+)$ /forum/jscripts/$1 [R=301,L]
反向引用$1需要引用一个捕获(括号中的表达式)

编辑:

您需要将其放置在此行上方:

RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
这将所有内容重定向到index.php以进行处理。
[L]
标志告诉它停止处理重写规则。

答案是:

RewriteRule ^(jscripts)/(.*) /forum/$1/$2 [R=301,L] 
花了一段时间,但最后,感谢Anthony的这一点:


反向引用$1需要引用一个捕获(括号中的表达式)。

emm它不起作用,我可能做错了什么,我把…标记放在其他重写规则旁边…你是否打开了
重写引擎?
?是的,我打开了,我还有下面的重写条件%{REQUEST_FILENAME}!-f RewriteCond%{REQUEST_FILENAME}!-d RewriteCond%{REQUEST_URI}!=/favicon.ico RewriteRule^(.*)$index.php?q=$1[L,QSA]能否将.htaccess的全部内容粘贴到问题中?将其移到上面似乎会阻止另一行的工作,但仍然没有重定向,
RewriteRule ^(jscripts)/(.*) /forum/$1/$2 [R=301,L]