简体   繁体   中英

Apache mod rewrite .htaccess problem

My site is a php based site, but I've added wordpress in a /blog/ folder. The .htaccess file below should allow the /blog/ folder to be accessed, but I get a 404 error saying that blog.php doesn't exist.

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{SCRIPT_FILENAME}  !\.(gif|jpg|png)$
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)/(.*)/$ /$1_$2.php [L]
    RewriteRule ^(.*)/$ /$1.php [L]
</IfModule>

Anybody able to help at all?

最后一个RewriteRule将您的请求重定向到/blog/index.php ,您应该添加一个RewriteCond来检查请求是否在博客文件夹中。

RewriteCond %{REQUEST_URI} !^/blog/.*

Adding

RewriteRule ^(blog) - [L]

to public_html/.htaccess after

RewriteEngine On

worked for me as well on a fresh Wordpress installation with Fantastico on a Hostgator account, with a blog.example.com subdomain.

I managed this using the code below, for some reason the conditionals that were suggested don't work (I HATE .htaccess)

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule ^(blog) - [L]
    RewriteCond %{SCRIPT_FILENAME}  !\.(gif|jpg|png)$
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)/(.*)/$ /$1_$2.php [L]
    RewriteRule ^(.*)/$ /$1.php [L]
</IfModule>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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