.htaccess 如何在一个htaccess文件中编写多个重写规则?

5jvtdoz2  于 2022-11-25  发布在  其他
关注(0)|答案(1)|浏览(130)

我正在创建一个博客网站,其中有6页index.php,about.php,contact.php,blog.php,event.php,和news.php。我想从网址中删除。php扩展名,并编写seo frendly网址。
来自blog.php单个博客显示在blogpost.php页面上来自event.php单个事件显示在eventpost.php页面上来自news.php单个新闻显示在newspost.php页面上
我的问题是只有第一个重写规则是工作。
如何在单个htaccess文件中编写多个重写规则。
下面是我的htaccess文件代码

Options -MultiViews

RewriteEngine On

RewriteRule ^([^/\.]+)/([^/\.]+)?$ eventpost.php?event_slug=$2
RewriteRule ^([^/\.]+)/([^/\.]+)?$ post.php?title_slug=$3
RewriteCond %{REQUEST_URI} !\.php$ [NC]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} [^/]$

RewriteRule ^(.*)$ $1.php [L]
0s0u357o

0s0u357o1#

试试这个

Options -MultiViews
RewriteEngine on

RewriteBase /

RewriteRule ^([^/\.]+)/([^/\.]+)?$ eventpost.php?event_slug=$2
RewriteRule ^([^/\.]+)/([^/\.]+)?$ post.php?title_slug=$3
RewriteCond %{REQUEST_URI} !\.php$ [NC]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} [^/]$
RewriteRule ^(.*)$ $1.php [L]

相关问题