简体   繁体   English

.htaccess从所有URL中删除子目录名称

[英].htaccess remove subdirectory name from all URLs

I was digging the net and haven't found any proper solution for this issue. 我正在挖网,并没有找到任何适当的解决方案来解决这个问题。 Basically, I want to remove subdirectory ( subdirname ) name from all URLs, eg: 基本上,我想从所有URL中删除子目录( subdirname )名称,例如:

http://test.com/subdirname/
http://test.com/subdirname/content/
http://test.com/subdirname/content/newpage

The website is based on Wordpress and located in /subdirname . 该网站基于Wordpress,位于/ subdirname I've got two .htaccess files, one in root directory: 我有两个.htaccess文件,一个在根目录中:

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d

#RewriteCond %{REQUEST_URI} !^(/var|/static)
#RewriteCond %{REQUEST_URI} !^(/index\.php|/var|/static)

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

RewriteCond %{HTTP_HOST} ^(www\.)?test\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/subdirname/
RewriteRule ^(.*)$ /subdirname/$1 [L]

and second in /subdirname/ directory: 和/ subdirname /目录中的第二个:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdirname/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdirname/index.php [L]
</IfModule>
# END WordPress

If anyone has some tips how to solve it, please advice. 如果有人有一些提示如何解决它,请建议。

You should be able to set up WordPress to display at your root domain but be installed in the subdirectory . 您应该能够将WordPress设置为在根域中显示,但应安装在子目录中 Just change ONLY the site URL under the Settings-> General screen. 只需更改“设置” - >“常规”屏幕下的站点URL即可。 Leave the subdirectory in the WordPress URL box. 将子目录保留在WordPress URL框中。 Then you would login at http://yoursite.com/subdirectory/wp-admin , but folks visit your site at http://yoursite.com . 然后您将登录http://yoursite.com/subdirectory/wp-admin ,但是大家会访问您的网站http://yoursite.com

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

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