[英]mod_rewrite rule for replacing string in URL
I would like to replace a string from old URL: 我想替换旧网址中的字符串:
http://www.homepage.com/projectname/public/ActionName.action
to 至
http://www.homepage.com/ActionName.action
or even 甚至
http://www.homepage.com/short
I got to this point (trying to it get shorten to http://www.homepage.com/ActionName.action
) 我到了这一点(尝试简化为
http://www.homepage.com/ActionName.action
)
RewriteEngine On
RewriteRule ^/projectname/public/(.*)$ http://www.homepage.com/$1 [R=301,L]
But I get a 404 error: 但我收到404错误:
The requested resource (/projectnameActionName.action) is not available.
I think you're looking for an internal
redirection. 我认为您正在寻找
internal
重定向。
So if you want to be able to put URL's like this in the browser: 因此,如果您希望能够在浏览器中输入如下网址:
http://www.homepage.com/ActionName.action
But show a page like this: 但是显示这样的页面:
http://www.homepage.com/projectname/public/ActionName.action
Then use this code in your.htaccess. 然后在your.htaccess中使用此代码。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+) http://www.homepage.com/projetname/public/$1 [NC,L]
Of course replace the domain name and folders to yours. 当然,将域名和文件夹替换为您的域名和文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.