【问题标题】:Rewrite URL with just company name with current htaccess file使用当前 htaccess 文件仅用公司名称重写 URL
【发布时间】:2016-10-23 17:51:12
【问题描述】:

首先我想说我很荣幸来到这里。我多年来一直使用这里给出的答案,它为我节省了很多时间。我一直在寻找我当前问题的答案,但没有运气。我相信答案不起作用,因为我将它添加到我当前所需的 .htaccess 文件中。我已经在我当前的软件程序(phpfox)论坛中询问过,但他们说无法完成。我将把它留给stackoverflow专家告诉我是否可以完成。这是我当前的 .htaccess 文件

Options -Indexes
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase  /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(file)/(.*) PF.Base/$1/$2
RewriteRule ^static/ajax.php index.php
RewriteRule ^themes/default/(.*) PF.Base/theme/default/$1
RewriteRule ^(static|theme|module)/(.*) PF.Base/$1/$2
RewriteRule ^(Apps|themes)/(.*) PF.Site/$1/$2

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

</IfModule>

以下是此业务页面 URL 的三个示例。

域名/目录/detail/302/name-of-business/overview/

域名/目录/详细信息/302/name-of-business/aboutus/

域名/目录/详细信息/302/name-of-business/contactus/

我想你明白了,但以防万一这里是不同的业务。

域名/目录/detail/303/name-of-business/overview/

现在对于这个业务页面,/directory/details 永远不会改变。 302 是该业务的数据库表中记录的主 ID。在同一记录中是企业名称。因此,如果我在浏览器 URL DomainName/directory/detail/302 中输入,即使 URL 末尾没有“业务名称/概述”,它仍会将我带到主概述页面。因此,我假设 php 代码会根据您在此特定业务上单击的菜单,将其从数据库中的 url 末尾抛出。

我的梦想是实现它

域名/企业名称/概述

域名/企业名称/联系人等...

但我什至很乐意至少删除目录/详细信息(我猜需要 id “302”,因为它是主要标识符……只是猜测)。

域名/302/业务名称/概述

我在这里尝试了许多不同的答案,但我觉得我也可能将它放在我当前的 .htaccess 文件中的错误行。提前感谢您的帮助和您的时间。

【问题讨论】:

    标签: .htaccess url url-rewriting phpfox


    【解决方案1】:

    尝试:

    Options -Indexes
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase  /
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(file)/(.*) PF.Base/$1/$2
    RewriteRule ^static/ajax.php index.php
    RewriteRule ^themes/default/(.*) PF.Base/theme/default/$1
    RewriteRule ^(static|theme|module)/(.*) PF.Base/$1/$2
    RewriteRule ^(Apps|themes)/(.*) PF.Site/$1/$2
    
    # Rewrite DomainName/303/... to DomainName/directory/detail/303/...
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(\d+)(/.*|$) index.php?q=directory/detail/$1$2 [L,QSA]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    
    </IfModule>
    

    DomainName/303/... 重写为DomainName/directory/detail/303/... 但仅适用于外部链接或一旦固定在您的页面中

    【讨论】:

    • 首先感谢您的帮助。它似乎没有做任何事情......我重新启动了服务器以防万一。但至少它没有像我 99% 的尝试那样使网站崩溃。我什至尝试在 $1$2 之间添加一个正斜杠,但没有成功。尽管我对您的陈述感到困惑,因为我希望(用您的话)为此...将 DomainName/directory/detail/303/... 重写为 DomainName/303/... 这与您所说的相反.我也不懂外部链接,除非您谈论人们将输入的内容或文本链接上的链接网址。现在我需要研究你的代码
    • 我只是想到了一些可能会损害我努力的事情。包含企业所有链接/图像的页面位于具有以下 URL 的页面上。
    • DomainName/directory/ 所以也许从这个页面开始是在搞砸 htaccess 吗?就像在风中扔飞镖:)
    • 我想得越多......业务目录是一个附加模块/应用程序所以也许这也影响它。
    • RewriteRule ^(Apps|themes)/(.*) PF.Site/$1/$2
    猜你喜欢
    • 2021-12-23
    • 2014-03-01
    • 2010-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 2013-04-22
    • 2017-04-08
    相关资源
    最近更新 更多