To get the url name and redirect in jQuery

Ranjit

I am using the below code for getting the current URL in jQuery.

var pathname = window.location.pathname;
console.log(pathname);

Now I have got the url like this

http://localhost/TantraProjects/CollectiveCraft/Repo/WebSite/index.php/crafts/t-lights.html

I want to convert the URL into this

http://localhost/TantraProjects/CollectiveCraft/Repo/WebSite/index.php

Is there any a way to convert into URL as above, whatever the URL is ?

shairya

Assuming you will always get index.php in your url and you want to remove everything after index.php, following code will work:

var url='http://localhost/TantraProjects/CollectiveCraft/Repo/WebSite/index.php/crafts/t-lights.html';
var b= url.split('index.php');
var newurl=b[0]+'index.php';
document.write(newurl);

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Java JSP get hostname (url) and then redirect if not

분류에서Dev

Redirect GET form with action in another url

분류에서Dev

JQuery URL GET 변수

분류에서Dev

SoundCloud - get song name from url

분류에서Dev

get domain name (base url without protocol)

분류에서Dev

How to get the url with application name in .net mvc?

분류에서Dev

Jquery Redirect

분류에서Dev

jQuery get last visited url in ajax page

분류에서Dev

Jquery $.get cuts url after hashtag

분류에서Dev

How to update a get parameter in a url with jquery

분류에서Dev

Redirect to URL from CoffeeScript

분류에서Dev

Express sendfile and redirect url

분류에서Dev

how to redirect the URL in magento?

분류에서Dev

jquery redirect on keydown is not working

분류에서Dev

Get dynamic count of visible elements by class name in jQuery

분류에서Dev

How to get the name's value from a input in jquery

분류에서Dev

jQuery - How to get JSON array name from nested JSON

분류에서Dev

Jquery Get a dynamic class name from a dynamic field

분류에서Dev

Jquery window.open get URL before close

분류에서Dev

URL redirect not working with .htaccess not working

분류에서Dev

.htaccess Redirect from URL with parameters

분류에서Dev

PHP Redirect Form to Custom URL

분류에서Dev

Redirect github page to different url

분류에서Dev

htaccess - redirect removing part of url

분류에서Dev

Onsubmit delay automatic url redirect

분류에서Dev

htaccess redirect dynamic URL to another dynamic URL

분류에서Dev

301 redirect for all get request

분류에서Dev

Redirect 301 on changed root name not working

분류에서Dev

Add/prepend a GET variable name using redirects in htaccess (to fix broken URL)