在 htaccess 中为多个页面重写 URL
Rewrite URLs in htaccess for multiple pages
我需要将两个不同页面的网址重定向到可读的网址。
我的 .htaccess 看起来像这样
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-/]+)$ blog-detail.php?url=
RewriteRule ^([a-zA-Z0-9-/]+)/$ blog-detail.php?url=
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ page.php?pid=
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/$ page.php?pid=
使用博客-detail.php 的第一个 url 工作正常。我的 URLS 可以像 mysite.com/latest-news-story
但是,第二个 page.php 不起作用,除非我删除博客详细信息重写规则。我怎样才能两者兼得?
您实际上可以将检查终止 /
的规则合并为一个。
所以,你实际上只需要以下两条规则。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/-]+)/?$ page.php?pid= [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ blog-detail.php?url= [QSA,L]
我需要将两个不同页面的网址重定向到可读的网址。 我的 .htaccess 看起来像这样
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-/]+)$ blog-detail.php?url=
RewriteRule ^([a-zA-Z0-9-/]+)/$ blog-detail.php?url=
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)$ page.php?pid=
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/$ page.php?pid=
使用博客-detail.php 的第一个 url 工作正常。我的 URLS 可以像 mysite.com/latest-news-story
但是,第二个 page.php 不起作用,除非我删除博客详细信息重写规则。我怎样才能两者兼得?
您实际上可以将检查终止 /
的规则合并为一个。
所以,你实际上只需要以下两条规则。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/-]+)/?$ page.php?pid= [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ blog-detail.php?url= [QSA,L]