2015-06-06 117 views
0

全部,htaccess重寫規則不起作用

我試圖通過htaccess重定向腳本重定向點擊。

下面是我的htaccess腳本。

Options +FollowSymlinks 
RewriteEngine on 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^post/(.*)/$ post.php?tag=$1 [L] 
RewriteRule ^search/(.*)$ search.php?tag=$1 [L] 

問題:索引和搜索頁面正在重定向。發佈頁面沒有被重定向。

請就如何解決它

回答

1

在你的根的.htaccess試試這個幫助:

Options +FollowSymlinks -MultiViews 
RewriteEngine on 

RewriteRule ^index\.php$ - [L] 

RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule^- [L] 

RewriteRule ^post/(.+)$ post.php?tag=$1 [L,NC,QSA] 

RewriteRule ^search/(.+)$ search.php?tag=$1 [L,NC,QSA] 
+0

這很好。但是在search.php?tag = news中出現的代碼很好,但搜索/新聞。它看起來非常混亂。任何其他設置需要完成? – user3138111

+0

對不起,這裏的規則笨拙嗎? 「搜索」規則是相同的「後」規則。 – anubhava

+0

不是規則。頁面search.php?tag = news顯示效果不錯,但搜索/新聞沒有正確顯示頁面。我已經驗證了html,它看起來是一樣的。 – user3138111

0

阿帕奇開箱不允許使用的htaccess的文件。如果你還沒有編輯你的/etc/apache2/sites-available/default文件,你需要這樣做。查找此塊的代碼:

<Directory /var/www/> 
      Options Indexes FollowSymLinks MultiViews 
      AllowOverride None 
      Order allow,deny 
      allow from all 
      # Uncomment this directive is you want to see apache2's 
      # default start page (in /apache2-default) when you go to/
      #RedirectMatch ^/$ /apache2-default/ 
    </Directory> 

,並更改AllowOverride NoneAllowOverride All。在您更改之後,您需要重新啓動Apache才能進行更改(service apache2 restart)。

買者

大多數時候,你會想通過做htaccess的文件可以更安全地通過Apache的配置文件(因此htaccess的文件在默認情況下忽略)做什麼。有關詳細信息,請參閱this post