简体   繁体   English

htaccess 301重写正则表达式

[英]htaccess 301 rewrite regex

I want to use htaccess to 301 redirect this: 我想使用htaccess来重定向这个:

http://olddomain.com/oldsubdir/pagename.aspx

to this: 对此:

https://www.newdomain.com/newsubdir/PAGENAME

changes: 变化:

  • http -> https http - > https
  • add 'www.' 添加'www。'
  • olddomain, newdomain, oldsubdir, and newsubdir are constants olddomain,newdomain,oldsubdir和newsubdir是常量
  • pagename is variable and will contain letters [a-zA-Z] and may or may not contain a '.' pagename是可变的,将包含字母[a-zA-Z],可能包含也可能不包含'。' (if there is a '.' then it will have alpha letters on both sides of it; such as abc.def.aspx where 'abc.def' is pagename, and '.aspx' is the suffix we're trying to strip off) (如果有'。'那么它的两边都会有字母字母;例如abc.def.aspx,其中'abc.def'是页面名称,'。aspx'是我们试图剥离的后缀关闭)
  • remove '.aspx' 删除'.aspx'
  • if possible, UPPERCASE pagename in the process (it's a stock symbol) 如果可能的话,过程中的UPPERCASE页面名称(它是股票代码)

I am assuming I will put the resulting redirect line in my .htaccess file in the root of olddomain.com. 我假设我将生成的重定向行放在olddomain.com根目录下的.htaccess文件中。 Thanks! 谢谢!

Try this code : 试试这段代码:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com$
RewriteRule ^oldsubdir/([a-zA-Z\.]+).aspx$ https://www.newdomain.com/newsubdir/$1 [R=301]

I don't think transform pagename to PAGENAME is possible. 我不认为将页面名转换为PAGENAME是可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM