2016-09-27 86 views
1

重寫問題與URL的同一起跑線名字我訪問某些網址中包含這些URL的相同的原料名稱的問題:URL在.htaccess

RewriteEngine On # Turn on the rewriting engine 

RewriteRule ^sections?$ sections.php [NC,L] 

RewriteRule ^sections/?$ sections.php [NC,L] 

RewriteRule ^sections/([0-9]+)/([a-zA-Z-.]+)/view?$ view_sections.php?id=$1&name=$2 [NC,L] 

RewriteRule ^sections/([0-9]+)/([a-zA-Z-.]+)/view/?$ view_sections.php?id=$1&name=$2 [NC,L] 

第2條規則工作,但最後2不要,它只是加載sections.php而不是視圖sections.php。當我使用Wamp它可以工作,但是當我在線上傳它不起作用。是否因爲php和apache的版本?

我的WAMP版本:

Apache的版本:2.4.9

PHP版本:5.5.12

的託管版本:

Apache的版本:Apache的/ 2.2.27

PHP版本:5.6.14

如果問題是版本問題,那麼可能的解決方案是什麼使它可以在託管版本中工作?

回答

1

嘗試像這樣,

Options -MultiViews 

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^sections?$ sections.php [NC] 
RewriteRule ^sections/?$ sections.php [NC,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

RewriteRule ^sections/([0-9]+)/([a-zA-Z-.]+)/view?$ view_sections.php?id=$1&name=$2 [QSA,NC] 
RewriteRule ^sections/([0-9]+)/([a-zA-Z-.]+)/view/?$ view_sections.php?id=$1&name=$2 [QSA,NC,L] 
+0

感謝的人!有效!我剛纔插入了這個(選項-MultiViews)。順便說一下,你能告訴我使用該行嗎?嘿嘿 – dmac

+0

以及它在這裏解釋得很好http://stackoverflow.com/questions/25423141/what-exactly-does-the-multiviews-options-in-htaccess –

+0

好吧。非常感謝!我的投票是你的。 – dmac