0

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.

Abhishek Gurjar
  • 7,426
  • 10
  • 37
  • 45
Ahmad Tahhan
  • 125
  • 14

4 Answers4

0

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]
Abhishek Gurjar
  • 7,426
  • 10
  • 37
  • 45
  • I assume you are trying this url in your browser example.com/بعض-النص-يذهب-هنا and you have category.php file stored in directory where you have your .htaccess file? – Abhishek Gurjar Jan 28 '17 at 10:57
  • Do you mean cached files, if so, I have cleared all the history and cached files and still getting the same result, I have contacted my host also and they said mod rewriting is enabled on Apache Server – Ahmad Tahhan Jan 28 '17 at 11:13
  • The htaccess file is in the root directory @Abhishek gurjar – Ahmad Tahhan Jan 28 '17 at 11:21
0

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)

Community
  • 1
  • 1
Sujal Patel
  • 2,444
  • 1
  • 19
  • 38
0

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

gseidel
  • 321
  • 2
  • 9
0

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.

Joe
  • 4,877
  • 5
  • 30
  • 51
  • No problem, glad I could help :) – Joe Jan 30 '17 at 10:02
  • What if I have more than one Category that I want to rewrite, I mean I have `category.php?post-title=$1` and I have `category2.php?post-title=$1` , I tried to do the same method but all is been redirected to one cateogry. – Ahmad Tahhan Feb 02 '17 at 09:46