2016-11-11 99 views
1

我一直嘗試重寫了Apache/2.4.17我用波紋管代碼CLEN url和工作正常在線,但開不工作在本地主機的mod_rewrite不工作在本地主機上的Apache/2.4.17

Options +FollowSymLinks -MultiViews 
RewriteEngine on 
RewriteBase /my_website_dir/ 
#remove extention 
RewriteRule ^([^/\.]+)/?$ $1.php [L,QSA] 

RewriteCond %{THE_REQUEST} /userprofile\.php\?u=([^\s&]+) [NC] 
RewriteRule^/userprofile/u/%1? [R=301,L] 
RewriteRule ^userprofile/u/([^/]+)/?$ /userprofile.php?u=$1 [L] 

以上代碼顯示此

找不到對象!

在此服務器上找不到請求的URL。如果您手動輸入網址 ,請檢查拼寫並重試。

如果您認爲這是服務器錯誤,請與網站管理員聯繫。 錯誤404本地主機的Apache/2.4.17(Win32的)的OpenSSL/1.0.2d PHP/23年6月5日

現在我也只能在本地主機嘗試這樣做,它的工作,但不能正確

Options +FollowSymLinks -MultiViews 
RewriteEngine on 
RewriteBase /my_website_dir/ 
#remove extention 
RewriteRule ^([^/\.]+)/?$ $1.php [L,QSA] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ userprofile.php?u=$1 [L] 

這裏就是我得到 本地主機/ my_website_dir/USERPROFILE/U /彼得 當我想要得到UI的參數值,得到這個userprofile/u/peter但我只需要返回彼得echo $_GET['u']

回答

1

更改您的最後一行:

RewriteRule ^userprofile/u/([^/]+)/?$ userprofile.php?u=$1 [L] 
+0

其中一個?如果第一個我已經做了,並且不工作@Croises –

+0

抱歉在工作,究竟是什麼原因可以在你的答案中解釋? –

+0

在'userprofile.php'之前''你的第一個鏈接指向root而不是rewritebase。並且在你從root用戶而不是從'userprofile/u /'重寫之後。 – Croises

相關問題