So I have a site where once there was a wiki structure in php
Now I have a completely clean site now started up from scratch (so no hidden .htaccess files etc. or other installed components) but need to redirect incoming url requests for the old site to a new html structure
I imagined I could do it using an .htaccess file
I have tried a variation of syntax in the .htaccess file for example:
<IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RedirectPermanent 3dprintfo.com/doku.php?id=3dproject2 http://3dprintfo.com/3dproject2.html
<IfModule mod_rewrite.c/>
<IfModule>
And for example:
RedirectPermanent 301 3dprintfo.com/doku.php?id=3dproject2 http://3dprintfo.com/3dproject2.html
RedirectPermanent http://3dprintfo.com/doku.php?id=3dproject2 http://3dprintfo.com/3dproject2.html
However nothing works I keep getting:
Not Found The requested URL was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
I have tried with and without http/301 etc.
Can anyone try to show me an example with multiple url redirects that I can try to implement using my above url names...
CodePudding user response:
This would be an example of a working redirection, as far as I understand your question:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?3dprintfo\.com$
RewriteCond %{QUERY_STRING} ^id=3dproject2$
RewriteRule ^/?doku\.php$ /3dproject2.html [R=301,QSD,L]
Of course it is possible to implement more general rules, so that you won't need a catalog of rules for each and every "old page". But that obviously depends on your link structure used previously.
In general I would suggest that you should implement such rule in the actual http server's host configuration and not in a distributed configuration file (".htaccess"). But above rule is written such that it works in both locations.
The first RewriteCond
might not be required, depends on what else is configured inside your http server.
UPDATE:
For what you ask in your first comment to this question I'd suggest something along these lines:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?3dprintfo\.com$
RewriteCond %{QUERY_STRING} ^id=([^&] )(?:&|$)
RewriteCond %1.html -f
RewriteRule ^/?doku\.php$ /%1.html [R=301,QSD,L]
This variant additionally checks if a file named for example 3dproject2.html
actually exists before rewriting to it.