.htaccess - Point string to php page and query -
i've been trying past 2-3 hours working don't have enough knowledge of regex.
i'm trying make url shortener, want point url domain.com/d5ds93x
domain.com/view.php?s=d5ds93x
i've been messing around .htaccess file , have now:
rewriteengine on rewritebase / rewriterule /(.*?)$ /view.php?s=$1 [l]
and sort of works, points right file string (d5ds93x) isn't passed on. view.php
file looks (for testing purposes):
<?php if (isset($_get['s']) && ctype_alnum($_get['s'])) { echo $_get['s']; } ?>
when visiting url blank page. if echo before if
rule displayed page works fine. data of passed on? or should add code detects data in url?
use this:
rewriteengine on rewritebase / # if request not valid directory rewritecond %{request_filename} !-d # if request not valid file rewritecond %{request_filename} !-f rewriterule ^/?(.+)$ view.php?s=$1 [l,qsa]
make leading slash optional rule works .htaccess apache config.
also restrict rule skip files , directories.
Comments
Post a Comment