我有一个在实时服务器上设置并运行的htaccess文件。一切都运行良好,但我必须添加一些特定的URL重定向到它。已在IIS web.config文件中设置了特定的重定向。一个例子:
<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>
我很难将其翻译成mt htaccess文件。我试过了:
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]
显然,program_consumer不是存在于根文档目录中任何位置的文件,但是site_programs确实存在并且作为无扩展名的PHP文件提供。对我缺少什么的想法?
答案 0 :(得分:0)
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]