更新时间:2023-02-23 09:25:15
如果您需要修改的能力的DocumentRoot
,这听起来像你只需要设置的DocumentRoot
到 /路径/要/页
。不过,如果你不能做到这一点,那么你可以在的.htaccess
If you have the ability to modify the DocumentRoot
, it sounds like you would just need to set your DocumentRoot
to /path/to/pages
. However, if you can't do that then you can try this in .htaccess
RewriteEngine On
RewriteRule ^/(.*)$ /pages/$1 [L,QSA]
以上是通用的,重定向的一切 /页
。如果您的网页确实被称为第一页第二页等等,那么这是更具体的:
The above is generic and redirects everything to /pages
. If your pages really are called "page1 page2 etc", then this is more specific:
RewriteRule ^/page([0-9]+)$ /pages/page$1 [L,QSA]
删除 [L]
如果你有更多的重写规则来处理。该 [QSA]
转发以及可能已经present其他任何的查询字符串参数。
Remove the [L]
if you have more rewrite rules to process. The [QSA]
forwards along any other querystring parameters that may have been present.
修改:对于用户输入 example.com/pages/page1
被重定向到 example.com/第1页
:
EDIT: For users to enter example.com/pages/page1
to be redirected to example.com/page1
:
RewriteEngine On
RewriteRule ^/pages/(.*)$ /$1 [L,QSA]
以上将在内部而不是重定向改变浏览器的地址栏。如果你想在地址栏更改,通知用户重定向发生,使用 [L,R = 301,QSA]
代替。