
Originally Posted by
fixyourself
php freaks.. patabang ta ko aning htaccess, pasensya mo 0 balance ko aning php og apache.. nag deploy rako..
provided the below folder structure
Code:
www (root)
...subfolder1
.......subfolder2
using htaccess how to redirect all request for subfolder1 to subfolder2
eg: localhost/subfolder1 --- if this is the request it should redirect to subfolder2, provided that subfolder2 has an index.
there two approach on this you can either go for dynamic approach or static approach
Dynamic:
PHP Code:
<IfModule mod_rewrite.c>
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Options -Indexes = prevents accessing directory without and index
Use php to check the uri and redirect it to where ever you intended to be
to access the URI you can use:
PHP Code:
$pu = parse_url($_SERVER['REQUEST_URI']);
$pathinfo = pathinfo($pu['path']);
PHP: parse_url - Manual
PHP: pathinfo - Manual
for dynamic websites mao ni ang usuall nga aproach... and the example above is how wordpress works
Static:
PHP Code:
<IfModule mod_rewrite.c>
Options -Indexes
RedirectMatch 301 ^/subfolder1/.*$ http://yoursite.com/subfolder2/
</IfModule>
PHP Code:
RedirectMatch 301 ^/subfolder1/.*$ http://yoursite.com/subfolder2/
pretty simple but not flexible, since we already declare Options -Indexes it will now return and error, you can now customize your error page by adding ErrorDocument line
PHP Code:
<IfModule mod_rewrite.c>
Options -Indexes
RedirectMatch 301 ^/subfolder1/.*$ http://yoursite.com/subfolder2/
ErrorDocument 404 /404.php
</IfModule>