Arash Yazdani
Arash Yazdani

Reputation: 75

htaccess url rewriting with multiple php vars in url

I need to create friendly urls for my website

need to change this url:
http://sitename.com/pn?title=1100متر+ویلایی+گلابدره&id=117

to this url, that contains utf-8 characters to
http://sitename.com/1100متر+ویلایی+گلابدره

I also need my variables like id, by using htaccess rewriting can i stil use them ?

is there a good doc that i can learn more about url rewriting ?
and is url rewriting good for website seo ?


THANKS

Upvotes: 1

Views: 204

Answers (2)

Abhishek Gurjar
Abhishek Gurjar

Reputation: 7476

Try it like this, I am unsure about the character you are passing and also you need to pass id in url too for rewriting. Please let me know if it works.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/([\d]+)$ pn?title=$1&id=$2 [QSA,NC,L]

Upvotes: 2

SPViradiya
SPViradiya

Reputation: 117

Here is your code

var currentURL = window.location.href;
var currentDomain = window.location.hostname;
function getParameterByName(name, url) {
    if (!url) {
      url = window.location.href;
    }
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}
window.history.pushState('page',document.title,getParameterByName('title'))

Upvotes: 0

Related Questions