[英]URL redirects in htaccess
I have a htaccess file that is set and running on a live server. 我有一个已设置并在实时服务器上运行的htaccess文件。 Everything is functioning fine with it but I have to add some specific URL re-directs to it. 一切正常,但我必须向其中添加一些特定的URL重定向。 The specific re-directs had been setup in an IIS web.config file. 特定的重定向已在IIS web.config文件中设置。 An example: 一个例子:
<rule name="URL re-direct" stopProcessing="true">
<match url="^program_consumer((\.cfm)|(\.php)|()+)((\?.*)|())$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="site_programs{R:7}" />
</rule>
I'm having a hard time translating this to mt htaccess file. 我很难将其翻译为mt htaccess文件。 I've tried: 我试过了:
AddDefaultCharset OFF
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Resolve .php file for extensionless php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
# Re-direct Non-file Non-directories
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([program_consumer]+)((\.cfm)|(\.php)|()+)((\?.*)|())$ http://{HTTP_HOST}/site_programs$1 [L,R=301]
Obviously, the program_consumer is not a file that exists anywhere in the root document directory, but the site_programs does exist and is served as an extension-less PHP file. 显然,program_consumer并不是根文档目录中任何位置的文件,但是site_programs确实存在,并且可以作为无扩展名的PHP文件使用。 Any thoughts on what I'm missing? 对我想念的东西有什么想法吗?
Your regex in RewriteRule
seems faulty and it needs to be placed before internal rewrite rule: 您在RewriteRule
正则表达式似乎有问题,需要将其放在内部重写规则之前:
AddDefaultCharset OFF
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(program_consumer\.(?:cfm|php))$ /site_programs/$1 [L,R=301,NC,NE]
# Resolve .php file for extensionless php urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.