HTACCESS - can you set two rules? ending in / and not ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: HTACCESS - can you set two rules? ending in / and not ?

Post by requinix »

Same way you'd do normal URL rewriting except using a [R=301].
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - can you set two rules? ending in / and not ?

Post by simonmlewis »

Sorry I really don't know.
Trust me, if I knew, I'd have done it. :)
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: HTACCESS - can you set two rules? ending in / and not ?

Post by requinix »

You've been doing them all along...

Code: Select all

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

Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^categ/([0-9]+)/([^/]+) /index.php?page=categ&c=$1&cname=$2&menu=sub [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1&menu=home [L]
RewriteRule ^$ index.php?page=home&menu=home [L]
I gave you something quite close: change it so it substitutes an actual URL you want to use (rather than the "-" which means leave it unchanged) and use [R=301] to make it redirect externally rather than rewrite internally.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - can you set two rules? ending in / and not ?

Post by simonmlewis »

Ok look, I've no idea.
I have tried so many things to point it to a URL and it never seems to work.

I was going to offer some suggestions, but on checking your 401 version, I cannot see how to point it to another URL.

IE.

Code: Select all

RewriteRule ^selector/ /error [L]
This doesn't work.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: HTACCESS - can you set two rules? ending in / and not ?

Post by requinix »

That's it. But you still have to include the [R=301] that I've mentioned a few times now.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - can you set two rules? ending in / and not ?

Post by simonmlewis »

Sorry? So that line is correct - but if it is, why do I need 301 as well?
Incidentally, if the URL is still too long, it fails. So I guess I need something that stops that.
ie.: /selector&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred&catname=fred

If someone spams us with that, it logs an error.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: HTACCESS - can you set two rules? ending in / and not ?

Post by requinix »

[R] tells mod_rewrite to change its usual behavior of just rewriting the URL internally (so Apache looks for files somewhere else) without doing any kind of redirection for the user. Typically [R] is for redirecting only, like using the 301, 302, or 307 HTTP status codes, but you can actually make it send any status code you want - 404, 500, whatever.

I guess that error happens before mod_rewrite can act. I don't know off the top of my head any way to prevent that from logging so I'd just Google the error message.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - can you set two rules? ending in / and not ?

Post by simonmlewis »

I have - didn't get a good idea of the issue, so came here to ask experts.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: HTACCESS - can you set two rules? ending in / and not ?

Post by requinix »

I'm not seeing any way you can work around it, which I'm not too surprised about because typically these things are caused by faulty redirections.

I'd just let it go. You're aware of the problem, and Google is getting non-200s (403s I bet) so they'll stop hitting the pages eventually.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - can you set two rules? ending in / and not ?

Post by simonmlewis »

So...
Forbidden
You do not have permission to access this document.
This is accepting for this page is it?
I assume Google therefore won't see it, and this won't cause anything in the Error Logs?
We'd love to point them to our personal error page, which is ..../error.

But if that cannot be done.....
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - can you set two rules? ending in / and not ?

Post by simonmlewis »

...(36)File name too long: access to /selector&catname...
Sadly we are still getting these in our error logs.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: HTACCESS - can you set two rules? ending in / and not ?

Post by requinix »

Right. You'll keep getting them until Google stops crawling the pages. Which it should because it doesn't keep pages that 403.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: HTACCESS - can you set two rules? ending in / and not ?

Post by simonmlewis »

Gotchya.
I'd like to know why it's crawling pages that don't even exist tho - and haven't existed for over a year.
Though perhaps people are posting out URLs that don't exist, just to spam us, hoping Google will try it on.

So there is no way to take users to a custom page like /error, if a "Filename is too long" ?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: HTACCESS - can you set two rules? ending in / and not ?

Post by requinix »

An ErrorDocument for 403 should take care of that.

Hmm... Maybe you can make that be a PHP script that does a

Code: Select all

header("HTTP/1.1 404 Not Found");
to hopefully "override" the 403.

And there's also their Webmaster Tools. You can probably get that URL (or /selector* URLs) removed from the list. And on that note, try adding it to a robots.txt too.
Post Reply