问题原文
原帖链接 · Francesco Marchioni · CC BY-SA 4.0
I need to place a rewrite rule in my .htaccess file so that requests for
http://example.com/jbossas/jboss-configuration
are redirected to:
http://example.com/jboss-server/jboss-configuration
So I have tried adding this rule into the .htaccess file:
RewriteRule ^jbossas/jboss-configuration jboss-server/jboss-configuration [R=301,L]
but it didn't work
RewriteRule ^/jbossas/jboss-configuration jboss-server/jboss-configuration [R=301,L]
didn't work either.
Is the rule correct? Or do I need to request a Web server restart to my Provider for changes to take effect? Note, I'm running Joomla 3 Web site.
已采纳解答
原帖链接 · MrWhite · CC BY-SA 4.0
Assuming you have a RewriteEngine On directive then...
RewriteRule ^jbossas/jboss-configuration jboss-server/jboss-configuration [R=301,L]
By itself, this directive would likely result in a malformed redirect, since the directory-prefix would be prefixed to the relative substitution string. For external redirects, the substitution string should start with a slash. However, this would also depend on whether you have a RewriteBase directive set, as this dictates the URL-path that is used, overriding the directory-prefix.
If you are not getting a redirect at all then it's likely that the directive has been put in the wrong place. An external redirect like this would need to go near the top of your .htaccess file, before the Joomla front-controller.
Not also, that the above regex matches any URL-path that simply starts /jbossas/jboss-configuration, not the URL exactly - if that is an issue?
RewriteRule ^/jbossas/jboss-configuration jboss-server/jboss-configuration [R=301,L]didn't work either.
This would only match if the directive was used in a server (or virtualhost) context. In a server context, the RewriteRule directive matches against the full URL-path, including the slash prefix. In a directory (or .htaccess) context it matches against the URL-path less the directory-prefix, so no slash prefix.
Try the following at the top of your .htaccess file:
RewriteEngine On
RewriteRule ^jbossas/jboss-configuration$ /jboss-server/jboss-configuration [R=302,L]
The RewriteEngine directive is not required if it is already present in the file. (It is more logical to have the RewriteEngine directive once at the very top, but that is not required.)
This is a 302 (temporary) redirect. Change this to a 301 (permanent) redirect - if that is the intention - only after you have confirmed that it works OK. This is to avoid the browser caching erroneous redirects whilst testing.
You will need to clear your browser cache before testing.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
