目前,当我访问example.com/index.php?page_id=6726
时,会显示所需的页面。我想将网址重写为example.com/newsletter
格式。
我当前的.htaccess文件包含以下内容:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example\.com\/newsletter [NC]
RewriteRule ^(.*)$ index.php?page_id=6726 [NC,QSA]
然而,我收到了一个未找到错误的页面。
如何进行重写工作,以便在我访问example.com/newsletter
时显示example.com/index.php?page_id=6726
的内容?
答案 0 :(得分:1)
RewriteEngine On
RewriteRule ^newsletter$ index.php?page_id=6272 [L,NC]
更一般地说,如果page_id
是变量,那么
RewriteRule ^newsletter/?(\d+)?$ index.php?page_id=$1 [L,NC]
会将访问者重定向到许多类似的页面,例如
example.com/newsletter/6272 -> example.com/index.php?page_id=6272
example.com/newsletter/272 -> example.com/index.php?page_id=272
example.com/newsletter/627 -> example.com/index.php?page_id=627
...