[英]htaccess rewrite rule is not working
All, 所有,
I'm trying to redirect the hits via htaccess redirect scripts. 我正在尝试通过htaccess重定向脚本重定向匹配。
Below is my htaccess scripts. 以下是我的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]
Issue : Index and search page are getting redirected. 问题:索引和搜索页面正在重定向。 Post page is not getting redirected.
帖子页面未重定向。
Please help on how to fix it 请帮忙解决
Try this in your root .htaccess: 在您的根.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 out of the box doesn't allow use of htaccess files. 开箱即用的Apache不允许使用htaccess文件。 If you haven't edited your
/etc/apache2/sites-available/default
file, you'll need to do so. 如果您尚未编辑
/etc/apache2/sites-available/default
文件,则需要进行编辑。 Look for this chunk of code: 查找以下代码块:
<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>
And change AllowOverride None
to AllowOverride All
. 然后将
AllowOverride None
更改为AllowOverride All
。 After you've changed that, you'll need to restart Apache for the changes to take place ( service apache2 restart
). 更改之后,您需要重新启动Apache才能进行更改(
service apache2 restart
)。
Caveat 警告
Most of what you'd want to do via htaccess files can be done more securely via the Apache configuration files (hence the htaccess files are ignored by default). 您希望通过htaccess文件执行的大多数操作都可以通过Apache配置文件更安全地完成(因此,默认情况下会忽略htaccess文件)。 See this post for details.
有关详细信息,请参见此帖子 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.