0

How can I achieve the URL pattern when the form is submitted

index.php

<form name="search_form" method="get" action="search-jobs/">
Skills : <input type="text" name="skills" />
Location : <input type="text" name="loc" />
<input type="submit" name="search" value="Search" />
<br />

.htacess

RewriteRule ^search-jobs/(.*)/(.*)?.php$ findjob4.php?skills=$1&loc=$2

how can I achieve this url / .htacess aliases when form is submited

Pattern url

www.example.com/search-jobs/{skills value}/{loc value}.php

sample

www.example.com/search-jobs/php/london.php

When i did this, its giving an error as Object not found and Error 404. basically : how i get the url pattern in above Pattern url in that format and in end of url .php should added

4

2 回答 2

1

将其操作设置为 index.php(同一页面),并将其添加到 index.php 的顶部:

if (isset ($_GET ['skills'])) {
    header('Location: /search-jobs/' . $_GET ["skills"] . '/' . $_GET ["loc"] . '.php');
}

<form name="search_form" method="get" action="index.php">
    Skills : <input type="text" name="skills" />
    Location : <input type="text" name="loc" />
    <input type="submit" name="search" value="Search" />
    <br />
</form>

根据 Rafee,您还必须从重写 url 中删除 .php。

于 2012-05-26T06:41:31.857 回答
0

无需修改任何 PHP 代码,只需将此代码放入您的 $DOCUMENT_ROOT/.htaccess 中替换您现有的代码:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+search-jobs/?\?skills=([^&]+)&loc=([^&]+) [NC]
RewriteRule ^ search-jobs/%1/%2.php? [R=302,L]

RewriteRule ^search-jobs/([^/]*)/([^.]*)\.php$ findjob4.php?skills=$1&loc=$2 [L,QSA,NC]

在您验证它在第一条规则中的工作R=302更改之后。R=301

于 2012-05-26T07:23:12.550 回答