Apache重定向url
重建我的站点后,一些URL(不再存在内容)必须重定向到/index.php。在旧版本中,我在/hu/fulbeloves+fulbevalova/目录中有一个index.php,该目录现在不存在。我想将请求重定向如下:Apache重定向url,apache,.htaccess,redirect,mod-rewrite,friendly-url,Apache,.htaccess,Redirect,Mod Rewrite,Friendly Url,重建我的站点后,一些URL(不再存在内容)必须重定向到/index.php。在旧版本中,我在/hu/fulbeloves+fulbevalova/目录中有一个index.php,该目录现在不存在。我想将请求重定向如下: /hu/fulbeloves+fulbevalova/=>/index.php?q=hu/fulbeloves-fulbevalova/ /hu/fulbeloves+fulbevalova/index.php?placeid=1234=>/index.php?q=hu/fulb
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-fulbevalova/index.php?placeid=1234
中,情况不可能如此,因此我将其重写为/index.php?q=hu/fulbeloves-fulbevalova&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(和所有.php请求)的404响应来自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/
索引仍为404。php@ArpadHart,您能告诉我您在这里点击的示例url是什么吗?@ArpadHart,尝试从RewriteRule^/index.php?q=%1/%2-%3/&%4[L]
TORewriteRule^index.php?q=%1/%2-%3/&%4[L]
一次?事实上,您将placeid作为独立参数获取的规则现在可以正常工作了!