[英]HTML remove url variables, NO PHP or JS solution
My site uses both PHP and the JS AJAX so I'm fairly familiar with them both, and I don't want a solution that includes them. 我的网站同时使用PHP和JS AJAX,因此我对它们都非常熟悉,而且我不想要包含它们的解决方案。 I have this page structure where all my users stay on just one landing php page, which then fetches the right content depending on the URL's p variable.
我有这个页面结构,我的所有用户只在一个登陆php页面上,然后根据URL的p变量获取正确的内容。
http://www.example.com/?p=about
http://www.example.com/?p=aMap-anothermap-evenAnothermap-lastelyTheFile
This page structure works great for me except that I don't know the right way to make a link that just removes the whole ?p=home
. 这个页面结构对我很有用,除了我不知道正确的方法来建立一个只删除整个
?p=home
。 Because I want my home/start page to be variable free. 因为我希望我的家/起始页是可变的。 I want it to be
我想要它
http://www.example.com/
rather than 而不是
http://www.example.com/?p=home
Now I could just make the link 现在我可以建立链接
http://www.example.com/?
And then just remove the ?
然后删除
?
with the JS pushState()
, but that would look pretty silly and would only work for JS users. 使用JS
pushState()
,但这看起来很傻,只适用于JS用户。
Let's say i would want to the do the above example with just the ?
假设我只想做上面的例子
?
then I could create a link like this. 然后我可以创建这样的链接。
<a href="?">Link</a>
<script src="SomeCoolPushStateScript"></script>
And I know from experience that this doesn't even work: 我从经验中知道这甚至不起作用:
<a href="">Link</a>
So here comes the question: How do I remove the ?variable=something
part of an URL when using an HTML href
? 所以问题就出现了:在使用HTML
href
时,如何删除?variable=something
URL的?variable=something
部分?
The path ./
should do the trick. 路径
./
应该做的伎俩。
<a href="./">Link</a>
If you want to preserve the main script name, like index.php
, you will have to include that name. 如果要保留主脚本名称(如
index.php
,则必须包含该名称。
<a href="index.php">Link</a>
Alternately, you could dynamically generate domain-relative or absolute URL's with PHP. 或者,您可以使用PHP动态生成域相对或绝对URL。
You don't need to use querystrings. 您不需要使用查询字符串。
<a href="/">Link</a>
would go to example.com's root. 会去example.com的根目录。
I don't recommend using "./"
. 我不建议使用
"./"
。 This would do what you want if the user is on a page that is in the root directory of your website (eg http://www.example.com/page.html
). 如果用户位于您网站根目录中的页面上(例如
http://www.example.com/page.html
),这将执行您想要的操作。 However, this would not work if they were on a page in a subdirectory. 但是,如果它们位于子目录中的页面上,则不起作用。 Eg if the user's on
http://www.example.com/hello/page.html
, it would just link to http://www.example.com/hello/
. 例如,如果用户位于
http://www.example.com/hello/page.html
,则只会链接到http://www.example.com/hello/
。
Using "/"
makes sure the user goes to the root of your website. 使用
"/"
可确保用户访问您网站的根目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.