Friday, September 27, 2019

multiple redirects with .htaccess



I want to do this




website.com/blog/index.php -> website.com/blog



website.com/admin/archief_login.php -> website.com/admin



this works with my code.
but I want to add this:



website.com/aa -> website.com/web/index.php?init=aa




for some reason the blog gets this redirect: website.com/blog/?init=blog



what is the best way to set these different rewrites?




RewriteEngine on Options All -Indexes
RewriteCond %{HTTP_HOST}
^websit.com$ [OR] RewriteCond
%{HTTP_HOST} ^www.website.com$
RewriteRule ^admin$

"http\:\/\/www.website.com\/admin/archief_login.php"
[R=301,L]



RewriteRule ^blog$
"http\:\/\/www.website.com\/blog/index.php"
[R=301,L]



DirectoryIndex client_login.php



RewriteRule

^screen-([a-zA-Z0-9_-]+).html$
index_client.php?screen=$1



RewriteRule
^invoice([a-zA-Z0-9_-]+).html$
make_invoice.php?id=$1



RewriteRule
^pack-([a-zA-Z0-9_-]+).html$
index_client.php?screen=pack_code&wwwcode=$1




Answer



You need to put the more "general" rules lower in the file so they don't match almost all of your URLs



RewriteRule ^(\w)$ /web/index.php?init=$1 [L, NC]
RewriteRule ^blog$ /blog/index.php [R=301,L]


The above will do




website.com/aa => website.com/web/index.php?init=aa
website.com/blog => website.com/web/index.php?init=blog


If you reverse the two rules you will get



website.com/aa => website.com/web/index.php?init=aa
website.com/blog => website.com/blog/index.php

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...