![](/img/trans.png)
[英].htaccess mod_alias and mod_rewrite redirects are ignored
[英]issue with URL redirection in Apache (mod_rewrite / mod_alias)
在Stack Exchange上有许多与使用mod_rewrite和mod_alias进行Apache配置有关的问题,但是我找不到我的问题的答案,所以这是另一个问题! ;)
我将旧网站迁移到了新位置。
以前可以通过URL访问文章,例如http://xxx/blog/index.php?post/YYYY/MM/DD/title
,因此在现有网页中有许多这种形式的链接。
现在,URL应该是http://xxx/post/YYYY/MM/DD/title
,所以只删除blog/index.php?
来自最终到达网址。
我想使用mod_alias和Redirect
子句,但是我在这里读到Redirect
子句是在RewriteRule
子句之后进行解释的,这对我来说是一个问题,因为我已经在使用RewriteRule
条件。
这是我当前的.htaccess文件:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
我试图以这种方式修改它:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/index.php? / [R=301,L]
RewriteRule ^(.*)$ index.php?$1
它几乎可以工作,除了:
http://xxx/blog/index.php?post/YYYY/MM/DD/title
被重定向/重写为http://xxx/blog/?post/YYYY/MM/DD/title
(注意?
),所以它不起作用 任何帮助都将非常受欢迎!
如果我使用以下规则:
RewriteRule ^/?blog/index\.php(.*)$ /$1 [R=301,L]
然后转到http://xxx/blog/index.php?test
带我去http://xxx/?test
,这几乎是正确的(询问标记仍然是一个问题)!
但是,当我尝试通过添加\\?
来匹配询问标记时\\?
:
RewriteRule ^/?blog/index\.php\?(.*)$ /$1 [R=301,L]
然后它就停止工作了……去那里: http://xxx/blog/index.php?test
只是把我留在那里!
这是为什么?
尝试将此规则添加到规则集的开头:
RewriteCond %{THE_REQUEST} \?post/([0-9]{4})/([0-9]{2})/([0-9]{2})/([^&\ ]*)
RewriteRule ^index\.php$ /post/%1/%2/%3/%4? [L,R=301]
这样看起来像:
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} \?post/([0-9]{4})/([0-9]{2})/([0-9]{2})/([^&\ ]*)
RewriteRule ^index\.php$ /post/%1/%2/%3/%4? [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.