海军活动班

时间:2018-08-27 14:31:31

标签: javascript php .htaccess

我正在使用以下脚本将class =“ active”添加到导航菜单,除非我使用htaccess删除.php扩展名,否则它可以正常工作。 这是代码:

$(document).ready(function () {    
    var CurrentUrl = window.location.origin+window.location.pathname;
    $('#NavMenu a').each(function(Key,Value)
        {
            if(Value['href'] === CurrentUrl)
            {
                $(Value).parent().addClass('active');
            }
        });
 });

我的.htaccess文件如下

# remove .php; use THE_REQUEST to prevent infinite loops
RewriteCond %{HTTP_HOST} ^www\.website\.com
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]

# remove index
RewriteRule (.*)index$ $1 [R=301]

# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]

# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

有没有建议的解决方案?我会很感激的!

1 个答案:

答案 0 :(得分:1)

尝试

var CurrentUrl = window.location.origin+window.location.pathname + '.php'; 

但是默认情况下,您将需要使用htaccess,否则将额外添加php扩展名