Apache redirect url

Viewed 64

After rebuilding my site some URLs (where contents no more exist) have to be redirected to the /index.php. In the older version I had an index.php in the /hu/fulbeloves+fulbevaloval/ directory, that directory does not exist now. I would like to redirect the requests as follows:

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

the first case works properly, but if index.php is in the URL then it fails with 404 (Not Found)

my .htaccess file:

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

Thanks for the advices!

1 Answers

With your shown samples/attempts, please try following. Make sure your htaccess Rules file and index.php files are present inside root directory. Also in your 2nd shown rewritten url /index.php?q=hu/fulbeloves-fulbevaloval/index.php?placeid=1234 it can't be the case so I have instead rewritten it to /index.php?q=hu/fulbeloves-fulbevaloval&placeid=1234 with 1st rule here.

Please make sure to clear your browser cache before testing your URLs.

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]

The 404 response by index.php (and all .php requests) came because of the VirtualHost setting: ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/run/php/php7.0-fpm.sock|fcgi://localhost/srv/

Solved after changing it to ProxyPassMatch ^/(index\.php(/.*)?)$ unix:/run/php/php7.0-fpm.sock|fcgi://localhost/srv/

Related