.htaccess - htaccess RewriteCond and RewriteRule -


i'm working on little php webiste , decided try give nice , cleans urls using htaccess file. i've read docs , created simple file few rules, things it's working partially.

this did: added rewriterule redirect "www.mysite.com/hello" "www.mysite.com/index.php?action=hello".

this working fine, problem want hide "index.php?action=" part if ever appears. if somoene imputs "www.mysite.com/index.php?action=hello" converted www.mysite.com/hello" in url field.

for wrote following:

    rewritecond %{the_request} ^[a-z]{3,9}\ /index\.php\?action=([^\ ]+)     rewriterule ^index\.php$ /%1? [r=301,l] 

sadly hides index.php part of url, "?action=" part still there.

what did wrong?

regards.

edit: i'm testing on local in wamp

you're pretty close. regex in rule trying match article.php condition says request must index.php, it's unlikely rule ever run. try:

rewritecond %{the_request} ^[a-z]{3,9}\ /index\.php\?action=([^&\ ]+) rewriterule ^index\.php$ /%1? [r=301,l]  rewritecond %{request_filename} !-d  rewritecond %{request_filename} !-f  rewritecond %{request_filename} !-l rewriterule ^(.+)$ index.php?action=$1 [qsa,l] 

and make sure rule before rule rewrites internally index.php.


Comments