【问题标题】:how to make multiple seo url using .htaccess?如何使用 .htaccess 制作多个 seo url?
【发布时间】:2017-03-03 16:06:23
【问题描述】:

在索引页面中,我是下面的 html 表单:

<form id="formname" class="form-inline" role="form" method="get" action="<?php echo htmlspecialchars(SITE_URL.'location'); ?>">
</form>

在此页面中,我有以下 js 脚本:

$("#formname").submit(function(event) {
    event.preventDefault();
    var loc = $("#basic option:selected").text();
    window.location.href = url+ loc;
});

提交此表单后,网址如下所示:

http://localhost/freelancer/chef/california

从这个页面:我点击这个网址:menu-details?mid=2

我希望这个网址应该是

http://localhost/freelancer/chef/california/2/menuname

从这个页面我点击这个 url:booking 页面(这是一个 booking.php 页面)

从此页面我使用$_POST 方法获取表单名称和值,但我希望url 看起来像这样:(然后我将使用$_GET 方法) `

http://localhost/freelancer/chef/california/2/menuname/booking

目前我正在使用以下 .htaccess 规则,但它仅适用于第一个 url 而不是我想要的所有 url。

.htaccess

ErrorDocument 404 /freelancer/chef/not-found.php
ErrorDocument 500 /freelancer/chef/not-found.php
RewriteEngine On        

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9_-]+)$ city.php?city=$1    [NC,L] 

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

更新:

ErrorDocument 404 /freelancer/chef/not-found.php
ErrorDocument 500 /freelancer/chef/not-found.php
RewriteEngine On        

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9_-]+)/?$ city.php?city=$1    [NC,L] 
#RewriteRule ^([A-Za-z0-9_-]+)/([\d]+)/([A-Za-z0-9_-]+)$ menu-details?mid=$2 [NC,L] 
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ menu-details.php?city=$1&mid=$2&title=$3
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

【问题讨论】:

    标签: php .htaccess mod-rewrite seo


    【解决方案1】:

    请添加这一行:

    RewriteRule ^([A-Za-z0-9_-]+)/([\d]+)/([A-Za-z0-9_-]+)$ menu-details?mid=$2    [NC,L] 
    

    【讨论】:

    • 让我试试吧
    • 好吧,从第一个链接页面http://localhost/freelancer/chef/california (city.php) 我点击这个网址&lt;?php echo SITE_URL."california/$mid/$link_title" ?&gt; 但它正在加载到city.php 页面上。它应该在“menu-details.php”页面上加载
    • 好吧,我改变了它,它正在菜单详细信息页面上工作:RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ menu-details.php?city=$1&amp;mid=$2&amp;title=$3
    • 现在 url 类似于:http://localhost/freelancer/chef/california/2/an-exploration-of-ramen 但如果我把这个 url http://localhost/freelancer/happiechef/california/ (见最后一个正斜杠)然后它显示我的自定义错误消息。如何使用.htaccess 接受last forward slash
    • 我已经更新了我的.htaccess 规则。现在我怎样才能从这个链接http://localhost/freelancer/chef/california/2/an-exploration-of-ramen去booking.php?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-31
    • 2021-04-11
    • 1970-01-01
    • 1970-01-01
    • 2018-09-10
    • 2021-07-23
    • 1970-01-01
    相关资源
    最近更新 更多