how to hide .php and id on url

时间:2016-02-12 20:47:44

标签: php apache .htaccess mod-rewrite

I want to change this URL:

$(function () {
      var url = window.location.search.match(/url=([^&]+)/);
      if (url && url.length > 1) {
        url = decodeURIComponent(url[1]);
      } else {
        url = "http://localhost:8080/SwaggerTest1/api/swagger.json";
      }

into this:

http://example.com/pages.php?sports_id=23

My code is:

http://example.com/pages/sports/23

2 个答案:

答案 0 :(得分:0)

Add this line to your .htacess

SELECT S.status_site AS [Status]
    ,COALESCE(count(L.lead_instance_id), 0) AS [Total Occurrences]
    ,COALESCE(SUM(L.Rate), 0) AS [Rate Sum]
    ,COALESCE(li.product_id, 0) AS [Product_id]
    ,COALESCE(li.afid, 0) AS [AFFILIATE_id]
FROM Status_Mapping S
LEFT OUTER JOIN lead_transactions L ON S.status_orignal = L.STATUS
LEFT OUTER JOIN lead_instance li ON li.lead_instance_id = L.lead_instance_id
WHERE li.product_id = 6
    AND li.afid = 27
GROUP BY S.status_site
    ,li.product_id
    ,li.afid

But I think it will not be possible to change the GET part to a slash. (Correct me if I am wrong).

答案 1 :(得分:0)

如果您还没有,则首先需要应用中的网址更改为/pages/sports/23。然后使用.htaccess将“漂亮”URL重写回真实URL。

要将/pages/sports/23重新编辑回/pages.php?sports_id=23,您可以执行以下操作:

RewriteRule ^pages/sports/23$ pages.php?sports_id=23 [L]

但是,您可能想要更通用的东西。但是如何通用?从你的问题不清楚哪些元素是可变的。像以下这样的东西可能为你工作......

RewriteRule ^([^/])+/([^/])+/(\d{3})+$ $1.php?$2_id=$3 [L]