【问题标题】:change url using htaccess, while two variables in url使用 htaccess 更改 url,而 url 中有两个变量
【发布时间】:2014-08-29 17:53:15
【问题描述】:

我的网址中有两个变量。 这是我的主页网址 --> subdomain.example.com/subdirectory/abc.php

如果变量可用,url 像这样 --> subdomain.example.com/subdirectory/abc.php?m=p&n=q abc.php页面通过获取这些变量生成不同的内容。

我为此使用 htaccess,它工作正常。 我需要像这样更改 url --> subdomain.example.com/subdirectory/p/q

问题是网站有一些页面分隔页面,如contact.php,privacy.php

对于该页面,我需要更改该网址,例如 subdomain.example.com/subdirectory/contact subdomain.example.com/subdirectory/privacy

当我输入网址 subdomain.example.com/subdirectory/contact 时, abc.php 正在获取第一个变量(m)=联系人。

我需要停止它并使用 htaccess 更改 url。 请帮我。谢谢。

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    尝试将这些规则添加到 htaccess 文件中/subdirectory/

    Options -Multiviews
    RewriteEngine On
    
    # Append the .php extension
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}.php -f
    RewriteRule ^ /%{REQUEST_URI}.php [L]
    
    # pass parameters to abc.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/([^/]+)/?$ abc.php?m=$1&n=$2 [L,QSA]
    

    【讨论】:

      猜你喜欢
      • 2013-12-24
      • 2017-10-01
      • 2011-02-03
      • 2011-08-23
      • 2015-02-18
      • 2013-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多