1

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

2
  • You just want to show this new url or want to redirect to new url? Commented Oct 22, 2016 at 7:09
  • i only want to change the urls name, not redirecting them Commented Oct 22, 2016 at 7:12

2 Answers 2

2

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]
Sign up to request clarification or add additional context in comments.

7 Comments

But you don't want to pass id to page please clarify!
of course i need to pass id to the page, i just need have a friendly url, this : kolbex.com/خوابگاه+برادران+صدرا/157 is great but my images and css won't load
So if you are passing id to page you need to specitfy in url like sitename.com/12 <- this is id, in your case after your title you need to pass id too /117 and for css and javascript use this tag in your head section <base href="http://www.w3schools.com/" >
i didn't put it on top of the page, my bad - you have +1 thanks man ;-)
|
0

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

2 Comments

this code only change the url after page loads, i need i have a friendly urls - i believe need to using htaccess

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.