skip to Main Content

I have a dayanmic website built in core PHP/MySql and hosted on one.com, I’m trying to make my URLs SEO Friendly by removing all Unnecessary signs from the URL, especially the variable ?someid=

I tried a lot of scripts using htaccess but nothing worked.

currently my url look like this: example.com/category.php?post-title=بعض-النص-يذهب-هنا

I want it to look like this: example.com/بعض-النص-يذهب-هنا

The title is stored in a MySql database.

as I mentioned I tried a lot of mod rewriting but nothing worked, here is one of the scripts I tried:

RewriteEngine On
RewriteBase /
RewriteRule ([^/]*).html category.php?post-title=$1

There is more scripts I tried, I can post them too if it’s important.

4

Answers


  1. Try it like this in root directory and mod-rewrite must be enabled for rewriting,

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([w-]+)$ category.php?post-title=$1 [QSA,L]
    
    Login or Signup to reply.
  2. Try below code

    <?php
    function curPageURL() {
    $pageURL = 'http';
    if ($_SERVER["HTTPS"] == "on") {
        $pageURL .= "s";
    }
    $pageURL .= "://";
    if ($_SERVER["SERVER_PORT"] != "80") {
        $pageURL .= $_SERVER["SERVER_NAME"] . ":" .
            $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
    } else {
        $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
    }
    return $pageURL;
    }
    ?>
    

    If any query follow below links

    How to remove the querystring and get only the url?

    Removing query string in PHP (sometimes based on referrer)

    Login or Signup to reply.
  3. If i just follow your example you just need this rule:

    RewriteEngine On
    RewriteBase /
    RewriteRule (.*) /category.php?post-title=$1
    

    But this will match every time the hole path.

    Maybe you should prefix your category paths like

    RewriteRule category/(.*).html /category.php?post-title=$1
    

    So every category has path like /category/بعض-النص-يذهب-هنا.html

    Login or Signup to reply.
  4. All you need to use is this:

    RewriteEngine On
    RewriteRule ^([^/]*)$ /category.php?post-title=$1 [L]
    

    It will leave you with your desired URL of: example.com/بعض-النص-يذهب-هنا. Just make sure you clear your cache before testing this.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search