Tuesday, 15 September 2015

.htaccess - htaccess - redirect domain.com/index.php?a=b to /b -



.htaccess - htaccess - redirect domain.com/index.php?a=b to /b -

i redirect url http://domain.com/index.php?section=abc http://domain.com/abc - without trailing slash. , @ same time prevent direct folder access

the sec thing works fine next code:

rewriteengine on rewriterule ^([a-za-z0-9_-]+)/$ / [r=301]

but first thing doesn't work correctly when try:

rewriterule ^([^/]*)/$ /index.php?section=$1 [l]

i glad if help me "little" problem. way - perchance apply 2 functions , add together 3rd rewrite rule redirect /abc/ /abc ...?

thanks :)

to send traffic index.php:

rewriteengine on rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(.*)$ /index.php?section=$1 [l]

this send requests files don't exist on filesystem index.php. way images, css, etc not redirected. means if have static file need serve can putting on server.

i'm not exclusively sure mean wanting disable direct folder access. mean people able see files in folder navigating them? if that's case, you'll want disable indexes.

options -indexes

you should create sure you've got directoryindex setting includes index.php. common:

directoryindex index.php index.html index.htm

if of files exist in folder that's requested without filename, rendered.

take @ apache manual more info these options:

http://httpd.apache.org/docs/current/mod/core.html#options - http://httpd.apache.org/docs/current/mod/mod_dir.html#directoryindex

.htaccess mod-rewrite redirect

No comments:

Post a Comment