0

好的,所以有很多问题与我想要的 SO 很接近,但似乎没有一个对我有用。我有一个旧网站,我正在尝试用 wordpress 网站替换。我已经从开发站点移动了 wordpress 站点,并使用了搜索和替换脚本来修复数据库中的所有 url。一切似乎都很好,所以我所做的就是将所有 wordpress 文件复制到文件夹root/wordpress中。

我仍然有位于根级别的旧站点文件,但我希望访问时的 url 是http://example.com而不是http://example.com/wordpress

所以我把这个htaccess文件添加到了根目录

.htaccess

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ [NC]
RewriteCond %{REQUEST_URI} !^/wordpress/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /wordpress/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$ [NC]
RewriteRule ^(/)?$ wordpress/index.php [L]

主页工作。当我访问http://example.com时,一切正常。但是,当我导航到另一个页面时,我被重定向到根 index.php 文件并且资源没有加载(图像、样式表、javascript 文件等)。管理页面也可以正常工作。所以我不知道为什么它不起作用。我在 wordpress 目录中也有一个很长的 htaccess 文件。

wordpress/.htaccess

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

# END WordPress

# BEGIN wtwp_cache
<IfModule mod_mime.c>

    # Text
    AddType text/css .css
    AddType application/x-javascript .js
    AddType text/html .html .htm
    AddType text/richtext .rtf .rtx
    AddType text/plain .txt
    AddType text/xml .xml

    # Image
    AddType image/gif .gif
    AddType image/x-icon .ico
    AddType image/jpeg .jpg .jpeg .jpe
    AddType image/png .png
    AddType image/svg+xml .svg .svgz

    # Video
    AddType video/asf .asf .asx .wax .wmv .wmx
    AddType video/avi .avi
    AddType video/quicktime .mov .qt
    AddType video/mp4 .mp4 .m4v
    AddType video/mpeg .mpeg .mpg .mpe

    # PDF
    AddType application/pdf .pdf

    # Flash
    AddType application/x-shockwave-flash .swf

    # Font
    AddType application/x-font-ttf .ttf .ttc
    AddType application/vnd.ms-fontobject .eot
    AddType application/x-font-otf .otf

    # Audio
    AddType audio/mpeg .mp3 .m4a
    AddType audio/ogg .ogg
    AddType audio/wav .wav
    AddType audio/wma .wma

    # Zip/Tar
    AddType application/x-tar .tar
    AddType application/x-gzip .gz .gzip
    AddType application/zip .zip
</IfModule>

<IfModule mod_expires.c>
    ExpiresActive On

    # Text
    ExpiresByType text/css A31536000
    ExpiresByType application/x-javascript A31536000
    ExpiresByType text/html A3600
    ExpiresByType text/richtext A3600
    ExpiresByType text/plain A3600
    ExpiresByType text/xml A3600

    # Image
    ExpiresByType image/gif A31536000
    ExpiresByType image/x-icon A31536000
    ExpiresByType image/jpeg A31536000
    ExpiresByType image/png A31536000
    ExpiresByType image/svg+xml A31536000

    # Video
    ExpiresByType video/asf A31536000
    ExpiresByType video/avi A31536000
    ExpiresByType video/quicktime A31536000
    ExpiresByType video/mp4 A31536000
    ExpiresByType video/mpeg A31536000

    # PDF
    ExpiresByType application/pdf A31536000

    # Flash
    ExpiresByType application/x-shockwave-flash A31536000

    # Font
    ExpiresByType application/x-font-ttf A31536000
    ExpiresByType application/vnd.ms-fontobject A31536000
    ExpiresByType application/x-font-otf A31536000

    # Audio
    ExpiresByType audio/mpeg A31536000
    ExpiresByType audio/ogg A31536000
    ExpiresByType audio/wav A31536000
    ExpiresByType audio/wma A31536000

    # Zip/Tar
    ExpiresByType application/x-tar A31536000
    ExpiresByType application/x-gzip A31536000
    ExpiresByType application/zip A31536000
</IfModule>
<FilesMatch "\.(?i:css|js|htm|html|rtf|rtx|txt|xml|gif|ico|jpg|jpeg|jpe|png|svg|svgz|asf|asx|wax|wmv|wmx|avi|mov|qt|mp4|m4v|mpeg|mpg|mpe|pdf|swf|ttf|ttc|eot|otf|mp3|m4a|ogg|wav|wma|tar|gz|gzip|zip)$">
    <IfModule mod_headers.c>
        Header set Pragma "public"
        Header append Cache-Control "public, must-revalidate, proxy-revalidate"
        Header unset ETag
    </IfModule>
</FilesMatch>
<FilesMatch "\.(?i:css|js|gif|ico|jpg|jpeg|jpe|png|pdf|swf|ttf|ttc|eot|otf)$">
    <IfModule mod_headers.c>
        Header unset Set-Cookie
    </IfModule>
</FilesMatch>
# END wtwp_cache

# BEGIN wtwp_security
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /wordpress/
    RewriteRule ^wp-admin/includes/ - [F,L]
    RewriteRule !^wp-includes/ - [S=3]
    RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
    RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
    RewriteRule ^wp-includes/theme-compat/ - [F,L]
</IfModule>
<Files "wp-config.php">
    Order allow,deny
    Deny from all
</Files>
Options -Indexes
# END wtwp_security

任何帮助将不胜感激谢谢!

4

0 回答 0