简体   繁体   English

将域重定向到没有 htaccess 的子文件夹

[英]Redirect domain to subfolder without htaccess

I have a dedicated server with many parked domains, my subfolders have the structure "domain.com/pages/username" and if the user purchases a own domain then do the redirect with this code in htaccess file:我有一个包含许多停放域的专用服务器,我的子文件夹具有结构“domain.com/pages/username”,如果用户购买了自己的域,则使用 htaccess 文件中的此代码进行重定向:

    RewriteCond% {HTTP_HOST} ^ mynewdomain\.com $ [NC] RewriteCond% {HTTP_HOST} ^ mynewdomain\.com $ [NC]
    RewriteCond% {DOCUMENT_ROOT} /pages/username/% {REQUEST_URI} /-d RewriteCond% {DOCUMENT_ROOT} /pages/username/% {REQUEST_URI} /-d
    RewriteRule [^ /] $% {REQUEST_URI}/ [R = 301, L]重写规则 [^ /] $% {REQUEST_URI}/ [R = 301, L] 
    RewriteCond% {ENV: REDIRECT_STATUS} ^ $ RewriteCond% {ENV: REDIRECT_STATUS} ^ $
    RewriteCond% {HTTP_HOST} ^ mynewdomain\.com $ [NC] RewriteCond% {HTTP_HOST} ^ mynewdomain\.com $ [NC]
    RewriteRule ^ (. *) $ /pages/username/$ 1 [QSA, L] RewriteRule ^ (. *) $ /pages/username/$ 1 [QSA, L]

But now as there are several domains and htaccess file size is getting larger.但是现在由于有几个域并且 htaccess 文件越来越大。 I wondered if something similar can be done from the domain configuration without editing the htaccess file.我想知道是否可以在不编辑 htaccess 文件的情况下从域配置中完成类似的操作。 I do not use subdomains, Can I use CNAME or something similar for new domains?我不使用子域,我可以对新域使用 CNAME 或类似的东西吗? htaccess file weight affects page load? htaccess 文件权重影响页面加载?

Is it possible?可能吗?

Thanks guys.多谢你们。

If you're the server administrator, you should not be using htaccess files for your configuration, you should be making the changes in the main config file for your server.如果您是服务器管理员,则不应使用 htaccess 文件进行配置,而应在服务器的主配置文件中进行更改。 If you're using Apache on Linux, this is typically located in /etc/apacheX/sites-available/ .如果您在 Linux 上使用 Apache,它通常位于/etc/apacheX/sites-available/中。 The exact same rules can be applied in a Directory section in the main configuration file.完全相同的规则可以应用于主配置文件的目录部分。

See here for information on when not to use htaccess files.有关何时不使用 htaccess 文件的信息,请参阅此处

You can use this .htaccess你可以使用这个 .htaccess

  # BEGIN WordPress
RewriteEngine On
RewriteBase /subdirectory-name/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdirectory-name/index.php [L]
# END WordPress

for more information please see this article https://welovewp.com/how-to-install-wordpress-in-a-subdirectory-with-htaccess-settings/有关更多信息,请参阅本文https://welovewp.com/how-to-install-wordpress-in-a-subdirectory-with-htaccess-settings/

Thank you谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM