2011-05-19 26 views
1

我想我的網站看起來是這樣的: http://www.example.com/about代替的web_url /指數[點] PHP頁面=約刪除 「?index.php頁面=文件名」

裏面我的索引[點] PHP中,我像這樣的導航鏈接:

<a href="index[dot]php?page=about">about</a> 
etc. 
... 
$view = $_GET['page']; 
switch($view){ 
case 'about': 
include("pages/about.html"); 
break; 

case 'project': 
include("pages/project.html"); 
break; 

... and so on 
} 

/* I have tried edit .htaccess file */ 
like this: 
order allow,deny 
allow from all 


Options +FollowSymlinks 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.*)$ $1.php [L] 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/ 
RewriteRule ^(([^/]+/)*)index\.php$ websiteurl/$1 [R=301,L] 

請幫忙!

感謝, 別名

+0

P/S:我有內部的index.php作爲導航鏈接如下: about project alias 2011-05-19 15:36:46

回答

0

這是我做的:

RewriteEngine on 
RewriteRule ^[^/.]*$ /run.php [L] 

然後我有一個從全局計算的文件路徑文件run.php:

$basename = $_SERVER['REDIRECT_URL']; 
$basename = ereg_replace('.*/', '', $basename); 
$basename = ereg_replace('\.html$', '', $basename); 
if($basename == '') { 
    $basename = 'index'; 
} 

$html_file = "$basename.html"; 
$php_file = "$basename.php"; 

然後你可以包含它,將其作爲模板閱讀,無論你做什麼。

+1

PS你不應該使用ereg_replace()了......它已經贊成的preg_replace() – JasonWoof 2011-05-19 14:10:06

+0

感謝JasonWoof的depricated!我試過你的代碼。 – alias 2011-05-19 15:22:37

+0

謝謝JasonWoof!我是新來的PHP。我已經嘗試過你的代碼幷包含到index.php中。 $ basename = $ _SERVER ['REDIRECT_URL']; $基名= preg_replace函數( '* /', '',$基名); $基名= preg_replace函數( '\ HTML $。', '',$基名);在index.php中:開關($基名){情況下 '':殼體 '索引':incluse( 「頁面/ index.html中」);打破; case'about':include(「pages/about.html」);打破; ......但是它在index.php中返回index.html。無論是點擊索引還是關於導航按鈕。 – alias 2011-05-19 15:34:18

0

試試這個:

$view = $_SERVER[REQUEST_URI]; 
switch($view){ 
case 'about': 
include("pages/about.html"); 
break; 
... 
} 

$ _ SERVER [REQUEST_URI]將得到HTTP主機URL的URI段,因此

www.example.com/uri -> $_SERVER[REQUEST_URI] == "uri" 
+0

謝謝** Yman!**我在localhost裏做這個。 HTTP://localhost/myproject/index.php的$ _ SERVER [ 'REQUEST_URI']顯示我/ myproject的/我有裏面的index.php導航鏈接:about project我不想index.php頁面=約是?顯示在url路徑中。先謝謝了! – alias 2011-05-19 15:20:41

+0

你可以像這樣添加爆炸: var uri_segments = explode($ _ SERVER ['REQUEST_URI']); switch(uri_segments [1]){case「about」:....} 您能夠手動編輯錨鏈接嗎?如果你使用上面的代碼,你可以把About Us Yman 2011-05-20 03:46:58