azumica Posted May 16, 2020 Share Posted May 16, 2020 Hi how can I make this URL clean http://localhost/?Active=View&PostCategory=1 i want to remove the ?,&, = make them into / this is the php code that manipulate the link <?php Class ControlURL{ public static $_page = "Active"; public static $_folder = Web_Body; public static $_params = array(); public static function cPage() { if(isset($_GET[self::$_page])){ return $_GET[self::$_page]; }else{ return 'index'; } } public static function getPage() { $page = self::$_folder.DS.self::cPage().".php"; $error = self::$_folder.DS."error.php"; if(is_file($page)){ return $page; }else{ return $error; } } } Quote Link to comment https://forums.phpfreaks.com/topic/310797-htaccess-and-php/ Share on other sites More sharing options...
gw1500se Posted May 16, 2020 Share Posted May 16, 2020 (edited) Since those are arguments for the request, I don't understand why you would want to do that. Please explain what you are trying to accomplish. A URL that looks like http://localhost//Active=View/PostCategory=1 makes no sense. If you rewrite it that way with .htaccess, what/how do you expect it to be processed? Edited May 16, 2020 by gw1500se Quote Link to comment https://forums.phpfreaks.com/topic/310797-htaccess-and-php/#findComment-1578065 Share on other sites More sharing options...
azumica Posted May 16, 2020 Author Share Posted May 16, 2020 4 minutes ago, gw1500se said: http://localhost/Active/View/PostCategory/1 something like that Quote Link to comment https://forums.phpfreaks.com/topic/310797-htaccess-and-php/#findComment-1578066 Share on other sites More sharing options...
gw1500se Posted May 16, 2020 Share Posted May 16, 2020 Fix the link rather than try to translate it. It still makes no sense to me. Quote Link to comment https://forums.phpfreaks.com/topic/310797-htaccess-and-php/#findComment-1578070 Share on other sites More sharing options...
azumica Posted May 16, 2020 Author Share Posted May 16, 2020 i have this RewriteRule RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*/|)([^/]*)$ index.php?Active=$2[L] but it only shows http://localhost/View i dont know to get the pass variable and its value which is the &PostCategory=1 Quote Link to comment https://forums.phpfreaks.com/topic/310797-htaccess-and-php/#findComment-1578072 Share on other sites More sharing options...
gw1500se Posted May 16, 2020 Share Posted May 16, 2020 (edited) You need to explain what you are trying to accomplish. I can not imagine why you want to do this with .htaccess. Perhaps we can suggest a better way. Edited May 16, 2020 by gw1500se Quote Link to comment https://forums.phpfreaks.com/topic/310797-htaccess-and-php/#findComment-1578073 Share on other sites More sharing options...
azumica Posted May 16, 2020 Author Share Posted May 16, 2020 I want a clean url. Thanks man i thought clean urls can be done with .htaccess Quote Link to comment https://forums.phpfreaks.com/topic/310797-htaccess-and-php/#findComment-1578074 Share on other sites More sharing options...
gw1500se Posted May 16, 2020 Share Posted May 16, 2020 Clean URL???? Quote Link to comment https://forums.phpfreaks.com/topic/310797-htaccess-and-php/#findComment-1578076 Share on other sites More sharing options...
maxxd Posted May 17, 2020 Share Posted May 17, 2020 I think you mean "pretty URL" or sometimes "friendly URL". Yes, you can do that with your .htaccess file, but it'll probably take some php coding as well. If you look at open-source CMSes and frameworks you'll get the basic idea - WordPress, Laravel, and Codeigniter are all examples I've personally used. Check out the .htaccess and index.php files, and follow the trail from there. You can also just google it and come up with plenty of examples. 1 Quote Link to comment https://forums.phpfreaks.com/topic/310797-htaccess-and-php/#findComment-1578092 Share on other sites More sharing options...
gizmola Posted May 17, 2020 Share Posted May 17, 2020 mod_rewrite will allow you to take a "pretty url" and parse it into the the parameters your site understands. It doesn't automagically translate a url with parameters into a "pretty" url. You need to do that yourself. Hopefully you understand this. 8 hours ago, azumica said: RewriteRule ^(.*/|)([^/]*)$ index.php?Active=$2[L] You have to understand regular expressions and capturing groups. 1 Quote Link to comment https://forums.phpfreaks.com/topic/310797-htaccess-and-php/#findComment-1578098 Share on other sites More sharing options...
azumica Posted May 18, 2020 Author Share Posted May 18, 2020 I guys i figured out my .htaccess is working now but i dont know how to change the redirect in <a href=""> this is my code echo "<li><a href=\"/?Active=View&PostCategory=".$cat['CategoryID']."\""; How can i redirect this in <a href= with this http://localhost/View/1 Quote Link to comment https://forums.phpfreaks.com/topic/310797-htaccess-and-php/#findComment-1578144 Share on other sites More sharing options...
azumica Posted May 18, 2020 Author Share Posted May 18, 2020 is this okay? "<li><a href=\"/View/".$cat['CategoryID']."\""; Quote Link to comment https://forums.phpfreaks.com/topic/310797-htaccess-and-php/#findComment-1578146 Share on other sites More sharing options...
gizmola Posted May 18, 2020 Share Posted May 18, 2020 Whatever lines up with your mod_rewrite rules. You should either interpolate your variable or not. You have a mix of the two (concatenation and interpolation). # Interpolation "<li><a href=\"/view/{$cat['CategoryID']}\">$somevar</a></li>"; #concatenation (use single quotes!) '<li><a href="/view/' . $cat['CategoryID'] . '">' . $somevar . '</a></li>'; Quote Link to comment https://forums.phpfreaks.com/topic/310797-htaccess-and-php/#findComment-1578155 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.