2014-05-05 81 views
0

我在root上有一個.htaccess文件。在根文件夾中有三個文件。向htaccess文件添加兩個重寫條件

  1. index.php文件上的index.php有兩種HREF事件和news.php文件
  2. article.php
  3. event.php

上article.php:

$articleId=123; 
$articleTitle='First Article'; 
echo '<a href="'.$articleId.'&'.str_replace(" ","-",$articleTitle).'">Read More</a>'; 

,並event.php:

$eventId=789; 
$eventTitle='First Event'; 
echo '<a href="'.$eventId.'&'.str_replace(" ","-",$eventTitle).'">Read More</a>'; 

以上兩種HREF的是對的index.php。

要處理重定向,我已經在htaccess文件上編寫了以下代碼。

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule (.*) article.php?arid=$1&$2 
RewriteRule (.*) event.php?eveid=$1&$2 

但是,當我添加第二個重寫線,系統沒有加載,當我刪除一個重寫空調系統工作正常。 任何人都可以幫我嗎?

在此先感謝,希望我明確提到這個問題。

+0

什麼是你想在你的瀏覽器的文章和事件看到的網址嗎? – anubhava

+0

@anubhavawhen文章:localhost/system/articleid-articletitle然後是event:localhost/system/eventid-eventtitle –

+0

這裏有什麼'/ system /'文件夾?你把你的PHP文件放在裏面嗎? – anubhava

回答

0

這是因爲您的服務器無法知道,例如12&my-article是文章還是事件。所以你的服務器採用與URL匹配的第一條規則。

所以,我認爲你必須區分這兩種網址,如article-12&my-articleevent-7&my-event。現在,.htaccess文件將是:

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule article-(.*) article.php?arid=$1&$2 
RewriteRule event-(.*) event.php?eveid=$1&$2 
0

你必須做出這樣 < A HREF = 「/藝術-123-articleTitle.html」>鏈接閱讀更多</A>

和它的規則(「藝術」是article.php)

RewriteRule ^art\-(\d+)\-(.*)\.html$ article.php?arid=$1&artitle=$2 [L]