Apache redirect url



在重建我的网站后,一些URL(内容不再存在(必须重定向到/index.php。在旧版本中,我在/hu/fulbowes+fulbevaval/目录中有一个index.php,该目录现在不存在。我想重定向请求如下:

  1. /hu/fulbeloves+fulbevaval/=>index.php?q=hu/fulbeloves-fulbevalval/
  2. /hu/fulbeloves+fulbevaval/index.php?placeid=1234=>index.php?q=hu/fulbeloves-fulbevaval/index.php?placeid=1234

第一种情况可以正常工作,但如果index.php在URL中,则会失败,出现404(未找到(

我的.htaccess文件:

RewriteEngine on
RewriteRule ^(.*)+(.*)$ /$1-$2 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

谢谢你的建议!

使用您显示的示例/尝试,请尝试以下操作。确保您的htaccess规则文件和index.php文件存在于根目录中。同样,在你的第二个显示的重写url/index.php?q=hu/fulbeloves-fulbevaloval/index.php?placeid=1234中,情况不可能是这样,所以我在这里用第一条规则将它重写为/index.php?q=hu/fulbeloves-fulbevaloval&placeid=1234

请确保在测试URL之前清除浏览器缓存。

RewriteEngine ON
RewriteCond %{THE_REQUEST} s/([^+]*)+([^/]*)/index..php?(S+)s [NC]
RewriteRule ^ /index.php?q=%1-%2/index.php&%3 [R=301,L]
RewriteRule ^(.*)+(.*)$ /$1-$2 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

index.php的404响应(以及所有.php请求(是因为VirtualHost设置:ProxyPassMatch ^/(.*.php(/.*)?)$ unix:/run/php/php7.0-fpm.sock|fcgi://localhost/srv/

更改为ProxyPassMatch ^/(index.php(/.*)?)$ unix:/run/php/php7.0-fpm.sock|fcgi://localhost/srv/后解决

最新更新