如果在URL中找到模式,则重定向HTACCESS

时间:2013-07-26 05:44:37

标签: .htaccess

我有网址http://www.mydomain.com/firstdir/seconddir/file.php或网址http://www.mydomain.com/firstdir/file.php以及其他一些网址。在现有的.htaccess文件中

RewriteEngine On
RewriteBase /
RewriteRule ^(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)/ - [L]
RewriteRule ^typo3$ typo3/index_re.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule .* /index.php [L]

如果模式 firstdir 位于网址路径中,我希望对网页XY的任何网址进行重定向。

每当我尝试构建任何rewriteCond时,整个网站都会被重定向... 谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

使用下面提到的代码。

RewriteRule ^firstdir/([^/\.]+)/?$ XY.php [L]

所以,完整的代码将是:

RewriteEngine On
RewriteBase /
RewriteRule ^firstdir/([^/\.]+)/?$ XY.php [L]
RewriteRule ^(typo3|typo3temp|typo3conf|t3lib|tslib|fileadmin|uploads|showpic\.php)/ - [L]
RewriteRule ^typo3$ typo3/index_re.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule .* /index.php [L]
相关问题