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
-
You just want to show this new url or want to redirect to new url?SPViradiya– SPViradiya2016-10-22 07:09:45 +00:00Commented Oct 22, 2016 at 7:09
-
i only want to change the urls name, not redirecting themArash Yazdani– Arash Yazdani2016-10-22 07:12:01 +00:00Commented Oct 22, 2016 at 7:12
Add a comment
|
2 Answers
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]
7 Comments
Arash Yazdani
i test it, and it worked, but urls become like: kolbex.com/خوابگاه+برادران+صدرا/157 can i do somthing that if url was sitename.com/pn?title=1100متر+ویلایی+گلابدره&id=117 it become sitename.com/1100متر+ویلایی+گلابدره automaticlly , i mean i don't want to have sitename.com/pn?title=1100متر+ویلایی+گلابدره&id=117 anymore ..
Abhishek Gurjar
But you don't want to pass id to page please clarify!
Arash Yazdani
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
Abhishek Gurjar
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/" >Arash Yazdani
i didn't put it on top of the page, my bad - you have +1 thanks man ;-)
|
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
Arash Yazdani
this code only change the url after page loads, i need i have a friendly urls - i believe need to using htaccess
SPViradiya
may be this would help stackoverflow.com/questions/14420597/…