2015-01-26 87 views
0

我在我的網站上創建了一個文本鏈接。如何顯示用戶定義的(漂亮)網址

  1. 當鏈路上的用戶點擊,就帶他到一個頁面:www.example.com/toronto_streets.php 但是,我想顯示爲www.example.com/toronto.on/

  2. 那麼當用戶從該頁面選擇一個街道的URL ,將URL www.example.com/street_landing_page.php?street=Option 但是,我想爲www.example.com/toronto.on/house-for-sale-option

我與編輯試圖要顯示的URL荷蘭國際集團.htacccess文件,但沒有工作......

這是我加入的.htaccess文件

RewriteEngine on 

RewriteRule ^toronto.on/house-for-sale-condo-mls/?$ house-for-sale-condo-mls.php [NC] #... 

所以將上面的行重定向到www.example.com/toronto.on/house-for-sale-condo-mls/www.example.com/house-for-sale-condo-mls.php

當林調用URL,www.example.com/toronto.on/house-for-sale-condo-mls/,即時得到這個錯誤:

請求的URL /toronto.on/house-for-sale-condo-mls未找到 此服務器上。


更新:

這是我目前的.htaccess文件。它將www.example.com/toronto.on重定向到一個名爲cate.php的頁面,其城市值='toronto'和省='on'。

Options +FollowSymLinks 
RewriteEngine on 

RewriteCond %{HTTP_HOST} ^example\.com 
RewriteRule ^(.*)$ example.com/$1 [R=permanent,L] 
+0

你需要對Apache擴展'mod_rewrite'做一些研究,你可以做類似的東西;你試圖寫入.htaccess的是什麼? – 2015-01-26 21:22:23

+0

,並且需要在您發送給客戶端的任何html中嵌入您的「友好」網址。如果您發送的HTML包含內部「醜陋」的URL,那麼mod_rewrite的大量修改都不可能在客戶端的瀏覽器中修復一個URL。 – 2015-01-26 21:23:58

+0

我編輯了這個問題,以反映我使用.htaccess文件 – MPK 2015-01-26 21:46:01

回答

0

在.htaccess,你會使用一組重寫規則,如下列:

Options +FollowSymLinks 
RewriteEngine On 
RewriteRule ^toronto.on(/*)$ /toronto_streets.php [L] 
RewriteRule ^toronto.on/house-for-sale-option /street_landing_page.php?street=option [L] 

您可以使用該網站來幫你測試重寫規則:click here

但是,正如其他人指出的那樣,網址欄中顯示的內容將是頁面請求的href。因此,html頁面上的鏈接應修改爲用戶友好的URL(例如/toronto.on/house-for-sale-option,而不是後端url /street_landing_page.php?street=option

+0

謝謝@Nick Vasic我編輯了我的.htaccess,仍然收到錯誤404。有什麼我失蹤? – MPK 2015-01-27 23:14:04

0

1)有2次失誤重寫規則,你在你的問題說:

RewriteEngine on 
RewriteRule ^/house-for-sale-condo-mls.php?$ /toronto/house-for-sale-condo-mls/ [QSA,NC,L] 

一個是在你的腦袋:**你需要有嵌入在你發送到客戶端的任何HTML您的「友好」的URL。 ** .htaccess不會讓漂亮的URL變得糟糕,它使得漂亮的URLs重新定向到真實的網站。 這意味着你的網站上的鏈接需要包含:

<a href="/house-for-sale-condo-mls.php">The Text</a> 

的seccond之一是缺少反斜槓。

同爲你的問題點1:

RewriteRule ^/toronto.on /toronto_streets.php [QSA,NC,L] 

IST可能是一個好主意,把另一個重寫規則像這樣在Top者的面前:

RewriteRule ^/toronto_streets.php /toronto.on [R=301,L] 

如果somethere鏈接不是更改(外部資源)它將用戶重定向到漂亮的URL。

+0

這是我當前的.htaccess文件。它將「www.example.com/toronto.on」重定向到一個名爲cate.php的頁面,其中城市值='toronto'和province ='on'。選項+ FollowSymLinks RewriteEngine on RewriteCond%{HTTP_HOST}^example \ .com RewriteRule ^(。*)$ http://www.example.com/$1 [R = permanent,L] – MPK 2015-01-30 00:10:29