[英]htaccess rewrite rule is not working
所有,
我正在嘗試通過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]
問題:索引和搜索頁面正在重定向。 帖子頁面未重定向。
請幫忙解決
在您的根.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]
開箱即用的Apache不允許使用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 None
更改為AllowOverride All
。 更改之后,您需要重新啟動Apache才能進行更改( service apache2 restart
)。
警告
您希望通過htaccess文件執行的大多數操作都可以通過Apache配置文件更安全地完成(因此,默認情況下會忽略htaccess文件)。 有關詳細信息,請參見此帖子 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.