Jump to content

.htaccess and PHP


azumica

Recommended Posts

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;
        }
    }


}

 

Link to comment
Share on other sites

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 by gw1500se
Link to comment
Share on other sites

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.

  • Thanks 1
Link to comment
Share on other sites

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.

  • Thanks 1
Link to comment
Share on other sites

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>';

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.