如何在地址栏php、.htaccess或javascript中完善url

如何在地址栏php、.htaccess或javascript中完善url,javascript,php,.htaccess,mod-rewrite,Javascript,Php,.htaccess,Mod Rewrite,这是我的.htaccess: <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine on ErrorDocument 404 /?page=404 # 1-level RewriteRule ^contact/{0,1}$ index.php?p=contact [QSA,L] RewriteRule ^displaydata/{0,1}$ index.php

这是我的.htaccess:

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine on
    ErrorDocument 404 /?page=404

    # 1-level
    RewriteRule ^contact/{0,1}$  index.php?p=contact [QSA,L]
    RewriteRule ^displaydata/{0,1}$  index.php?p=displaydata [QSA,L]
    RewriteRule ^log-in/{0,1}$  index.php?p=log-in [QSA,L]
    RewriteRule ^log-out/{0,1}$     ?p=log-out [QSA,L]

    # newweb.com/contact# = newweb.com/contact/#
    #RewriteRule ^contact/(.*)?$ $1
    #RewriteRule ^displaydata/(.*)?$ $1
    #RewriteRule ^log-in/(.*)?$ $1
    #RewriteRule ^log-out/(.*)?$ $1


    ####
    # set URI to /index.php/200 if query string is id=200
    RewriteCond %{QUERY_STRING} (?:^|&)id=(200|1)(?:&|$) [NC]
    RewriteRule ^(index\.php)/?$ $1/%1 [NC]

    # set SECURED var to 1 if URI is /index.php/200
    SetEnvIfNoCase Request_URI "^/index\.php/(200|1)" SECURED

    # enforce auth if SECURED=1
    AuthType Basic
    AuthName "Login Required"
    AuthUserFile /full/path/to/passwords
    Require valid-user
    Order allow,deny
    Allow from all
    Deny from env=SECURED
    Satisfy any
    #####
    # all other cases
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .+ -  [L]
    </IfModule>

试试这个,有时候可能有用。首先将其放在您的
下:

当您以这种方式使用任何URL时,您将能够获得:

"http://example.com/my/path/#".substr(-2)  // "/#"
因此,将此作为一件事,您可以:

var url = "http://example.com/my/path/#";
if (url.substr(-2) == "/#")
  window.location.href = url.substr(-2) + "#";

部分设置
标记.Hi。蒙塔希尔·阿肯。我已经添加了它,但不起作用仍然是同一个问题?当有人试图在最终url中添加“/”时,您有什么方法可以返回或不更改页面?不太可能。在我的网站中,我总是使用
,这样所有的链接都是绝对指向根的。所以,无论用户尝试做什么,都不重要。相同级别的css、弹出窗口、登录、联系人、显示数据文件夹是newweb文件夹的子文件夹。newweb文件夹@TríĐ中的index.phpứ你在使用linux机器吗?至少,服务器托管在哪里?Im使用Windows。这是localhost:8080当有人试图在最终url newweb.com/displaydata/#处添加“/”时,您有什么方法可以选择返回newweb.com/displaydata#还是不更改页面?@TríĐứ你喜欢什么?方法?
"http://example.com/my/path/#".substr(-2)  // "/#"
var url = "http://example.com/my/path/#";
if (url.substr(-2) == "/#")
  window.location.href = url.substr(-2) + "#";