2016-11-08 114 views
1

我知道有一千关于这个重复的帖子,但迄今没有任何工作。重写规则与网址参数

我试图用一个重写规则变换/articulo.html?id=friendly-url/articulo/friendly-url

这是我在.htaccess用过没有成功:

RewriteEngine On 
RewriteRule ^articulo/(.*)$ /articulo.html?id=$1 [L] 

编辑:

这是寻找id参数的js:

var getUrlParameter = function getUrlParameter(sParam) { 
    var sPageURL = decodeURIComponent(window.location.search.substring(1)), 
     sURLVariables = sPageURL.split('&'), 
     sParameterName, 
     i; 
     console.warn(sPageURL); 
     console.warn(sURLVariables); 

    for (i = 0; i < sURLVariables.length; i++) { 
     sParameterName = sURLVariables[i].split('='); 

     if (sParameterName[0] === sParam) { 
      return sParameterName[1] === undefined ? true : sParameterName[1]; 
     } 
    } 
}; 

回答

2

试试看像这样,

Options -Multiviews 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^articulo/(.*)$ articulo.html?id=$1 [L] 
+0

不,结果是一样的。它加载了articulo.html,因为路由改变而没有css和js。寻找id参数的js也不起作用。 – cerealex

+0

要正确加载css和js,请在头部使用'''。 –

+0

虽然有效,但它不能解决脚本无法通过URL更改检查ID的问题。我想这是预期的方式,我需要重构代码以查找ID后面的/? – cerealex