Page 1 of 1

htaccess - not allowing /blog to work

Posted: Tue Mar 01, 2016 5:53 am
by simonmlewis
We are trying to use this code to allow the Blog to have it's own URL in the site, but while preventing dodgy URLs too.

Why does this reroute "/blog" to "/blog/?page=blog".

Would this code cause that?

Code: Select all

RewriteRule ^(blog)($|/) - [QSA]
# Remove multiple slashes after domain
RewriteCond %{HTTP_HOST} !=""
RewriteCond %{THE_REQUEST} ^[A-Z]+\s//+(.*)\sHTTP/[0-9.]+$ [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]+\s(.*/)/+\sHTTP/[0-9.]+$
RewriteRule .* http://%{HTTP_HOST}/%1 [R=301,L]

# Remove multiple slashes anywhere in URL
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]



Re: htaccess - not allowing /blog to work

Posted: Tue Mar 01, 2016 6:26 am
by Celauran
What's the incoming request? I don't see anything there that would rewrite /blog to /blog/?page=blog but the QSA on the first rule would maintain the ?page=blog if it already existed.

Re: htaccess - not allowing /blog to work

Posted: Tue Mar 01, 2016 6:33 am
by simonmlewis
This is it from the top.

Oddly it's the same as one of our UK sites, and that has no issue.

Code: Select all

DirectoryIndex index.php index.html index.htm
order allow,deny
allow from all 

Options +FollowSymLinks
Options +Indexes
RewriteEngine On

ErrorDocument 404 /custom_404.php
# RewriteCond %{HTTPS} !=on
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^(blog)($|/) - [QSA]
# Remove multiple slashes after domain
RewriteCond %{HTTP_HOST} !=""
RewriteCond %{THE_REQUEST} ^[A-Z]+\s//+(.*)\sHTTP/[0-9.]+$ [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]+\s(.*/)/+\sHTTP/[0-9.]+$
RewriteRule .* http://%{HTTP_HOST}/%1 [R=301,L]

# Remove multiple slashes anywhere in URL
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

Re: htaccess - not allowing /blog to work

Posted: Tue Mar 01, 2016 6:39 am
by Celauran
The question about the incoming request remains, though. What are you trying to rewrite?

[text]RewriteRule ^(blog)($|/) - [QSA][/text]
Doesn't really do anything.

Re: htaccess - not allowing /blog to work

Posted: Tue Mar 01, 2016 6:49 am
by simonmlewis
It's so that if someone goes to www.website.co.uk/blog, it goes to the blog folder where it has Wordpress's structure.
We use this on all our websites and this code makes that work. Or it did!

Re: htaccess - not allowing /blog to work

Posted: Tue Mar 01, 2016 7:41 am
by Celauran
simonmlewis wrote:It's so that if someone goes to http://www.website.co.uk/blog, it goes to the blog folder where it has Wordpress's structure.
WordPress. That's maybe relevant. Are you sure that's not where the ?page=blog is coming from? WordPress has its own set of rewrite rules.

Re: htaccess - not allowing /blog to work

Posted: Tue Mar 01, 2016 7:45 am
by simonmlewis
Absolutely certain. Because this is BEFORE I have even had a chance to get to run the Install for Wordpress.
normally you upload the files. go to /blog, then you see the form to enter the database credentials.

I'm not even getting to that stage!

Re: htaccess - not allowing /blog to work

Posted: Tue Mar 01, 2016 7:49 am
by Celauran
There's nothing in your htaccess above that would be adding ?page=blog. The QSA on the blog rule would keep it, but it would have to already be there.

Re: htaccess - not allowing /blog to work

Posted: Tue Mar 01, 2016 7:53 am
by simonmlewis
Sorry I don't understand.
So you are saying there is nothing above that rule that would hinder it working.
We have PHP scripts that do stuff, like set URLs to be lowercase, and redirect if a product is not found, but nothing that does that. the other site we have that has very similar code indeed, works a treat with the same extra PHP files.

I just don't get it. When you first upload Wordpres, it doesn't install a HTACCESS does it. OR shoudl it?

Re: htaccess - not allowing /blog to work

Posted: Tue Mar 01, 2016 7:54 am
by simonmlewis
Well I'll be damned. It needed the extra HTACCESS before even running.

I just pinched this from another site, and uploaded it and it now works (ready to run the install).

Code: Select all

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

# END WordPress