Wordpress Rewrite rules and access to Stats

apps

#1

Hi,

I have Wordpress 1.5 installed and use “/category/postname/” as my permalink structure. (percentage signs removed for this post)

I have been unable to access my stats and support added the following lines to my mod rewrite rules in the .htaccess file:
RewriteCond %{REQUEST_URI} !^/stats/(.)$
RewriteCond %{REQUEST_URI} !^/failed_auth.html$
RewriteRule ^.
$ - [L]

This had the desired effect of allowing me to access the stats but also had the undesirable effect of stopping ALL links/pages except my index page from working!

Removing the last line, from the three above,allows access to the pages but does not allow stats access. Currently I am using two .htaccess files and renaming them when I want to check my stats!

I know other customers have WP installed and I was wondering whether anybody had a better solution?

TIA
Planetphillip

Here are the rules used in my original .htaccess file:

BEGIN WordPress

RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [S=54] RewriteRule ^(links)/trackback/?$ /index.php?pagename=$1&tb=1 [QSA,L] RewriteRule ^(links)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L] RewriteRule ^(links)/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L] RewriteRule ^(links)/page/?([0-9]{1,})/?$ /index.php?pagename=$1&paged=$2 [QSA,L] RewriteRule ^(links)/?([0-9]+)?/?$ /index.php?pagename=$1&page=$2 [QSA,L] RewriteRule ^(always-looking-for-2)/trackback/?$ /index.php?pagename=$1&tb=1 [QSA,L] RewriteRule ^(always-looking-for-2)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L] RewriteRule ^(always-looking-for-2)/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L] RewriteRule ^(always-looking-for-2)/page/?([0-9]{1,})/?$ /index.php?pagename=$1&paged=$2 [QSA,L] RewriteRule ^(always-looking-for-2)/?([0-9]+)?/?$ /index.php?pagename=$1&page=$2 [QSA,L] RewriteRule ^(about)/trackback/?$ /index.php?pagename=$1&tb=1 [QSA,L] RewriteRule ^(about)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L] RewriteRule ^(about)/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L] RewriteRule ^(about)/page/?([0-9]{1,})/?$ /index.php?pagename=$1&paged=$2 [QSA,L] RewriteRule ^(about)/?([0-9]+)?/?$ /index.php?pagename=$1&page=$2 [QSA,L] RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L] RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L] RewriteRule ^page/?([0-9]{1,})/?$ /index.php?&paged=$1 [QSA,L] RewriteRule ^comments/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1&withcomments=1 [QSA,L] RewriteRule ^comments/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1&withcomments=1 [QSA,L] RewriteRule ^comments/page/?([0-9]{1,})/?$ /index.php?&paged=$1 [QSA,L] RewriteRule ^search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?s=$1&feed=$2 [QSA,L] RewriteRule ^search/(.+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?s=$1&feed=$2 [QSA,L] RewriteRule ^search/(.+)/page/?([0-9]{1,})/?$ /index.php?s=$1&paged=$2 [QSA,L] RewriteRule ^search/(.+)/?$ /index.php?s=$1 [QSA,L] RewriteRule ^category/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&feed=$2 [QSA,L] RewriteRule ^category/(.+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&feed=$2 [QSA,L] RewriteRule ^category/(.+)/page/?([0-9]{1,})/?$ /index.php?category_name=$1&paged=$2 [QSA,L] RewriteRule ^category/(.+)/?$ /index.php?category_name=$1 [QSA,L] RewriteRule ^author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?author_name=$1&feed=$2 [QSA,L] RewriteRule ^author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?author_name=$1&feed=$2 [QSA,L] RewriteRule ^author/([^/]+)/page/?([0-9]{1,})/?$ /index.php?author_name=$1&paged=$2 [QSA,L] RewriteRule ^author/([^/]+)/?$ /index.php?author_name=$1 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&day=$3&feed=$4 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&day=$3&feed=$4 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /index.php?year=$1&monthnum=$2&day=$3&paged=$4 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&day=$3 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&feed=$3 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&feed=$3 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /index.php?year=$1&monthnum=$2&paged=$3 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2 [QSA,L] RewriteRule ^([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&feed=$2 [QSA,L] RewriteRule ^([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&feed=$2 [QSA,L] RewriteRule ^([0-9]{4})/page/?([0-9]{1,})/?$ /index.php?year=$1&paged=$2 [QSA,L] RewriteRule ^([0-9]{4})/?$ /index.php?year=$1 [QSA,L] RewriteRule ^(.+)/([^/]+)/trackback/?$ /index.php?category_name=$1&name=$2&tb=1 [QSA,L] RewriteRule ^(.+)/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&name=$2&feed=$3 [QSA,L] RewriteRule ^(.+)/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&name=$2&feed=$3 [QSA,L] RewriteRule ^(.+)/([^/]+)/page/?([0-9]{1,})/?$ /index.php?category_name=$1&name=$2&paged=$3 [QSA,L] RewriteRule ^(.+)/([^/]+)/?([0-9]+)?/?$ /index.php?category_name=$1&name=$2&page=$3 [QSA,L] RewriteRule ^(.+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&feed=$2 [QSA,L] RewriteRule ^(.+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&feed=$2 [QSA,L] RewriteRule ^(.+)/page/?([0-9]{1,})/?$ /index.php?category_name=$1&paged=$2 [QSA,L] RewriteRule ^(.+)/?$ /index.php?category_name=$1 [QSA,L]

END WordPress

Phillip
http://www.planetphillip.com/
Commentary and Analysis of Sci-Fi Single Player First Person Shooters


#2

I’ve had WP installed for almost a year now and never had any trouble accessing my stats. What directory is WP installed it? What plugins do you have installed?


MacManX.com
I don’t work here. I’m just your typical support forum volunteer.


#3

It’s installed in the root and I have the following plugins installed and activated:
Custom Posts Per Page, Obfuscate E-mail, Recent Comments, Recent Posts, Theme Switcher and Preview Theme.

TIA
PlanetPhillip

Phillip
http://www.planetphillip.com/
Commentary and Analysis of Sci-Fi Single Player First Person Shooters


#4

You may want to post this over in the WordPress Support Forums.


MacManX.com
I don’t work here. I’m just your typical support forum volunteer.


#5

Posting there was plan B. I thought I’d try here first.

Thanks anyway.

PlanetPhillip

Phillip
http://www.planetphillip.com/
Commentary and Analysis of Sci-Fi Single Player First Person Shooters


#6

The very last rule is causing the trouble with accessing stats:

RewriteRule ^(.+)/?$ /index.php?category_name=$1 [QSA,L]Basically, it matches “/anything” or “/anything/” where “anything” is any sequence of characters, including the word “stats”

And that line is probably there because of your permalink structure or the plugins.

If you insist on having the category name be the first part of the path, then you will need to do modify the original .htaccess so it looks like this:

[code]
RewriteEngine On
RewriteBase /

no substitution in order to access real files or directories

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]

no substitution in order to access site statistics

RewriteCond %{REQUEST_URI} ^/stats/(.*)$ [OR]

no substitution in order to access default Unauthorized error document

RewriteCond %{REQUEST_URI} ^/failed_auth.html$ [OR]

skip substitution, see RewriteCond directives above

RewriteRule ^.*$ - [S=54]
… rest of RewriteRules follow …
[/code]This structure has the logic like so:

IF filename is a file OR filename is a directory OR uri starts with '/stats/anything' OR uri is '/failed_auth.html' THEN skip next 54 substitution rules ELSE process substitution rules that followBy default, all RewriteCond tests must be true (AND) however appending the OR flag makes it optional instead.

To access your stats, use:
http://example.com/stats/

This will not work:
http://example.com/stats
Because then the Wordpress rules apply and it gets rewritten to:
http://example.com/index.php?category_name=stats

It would be a good idea to leave the comments (lines starting with #) so you know why they are there.

:cool: Perl / MySQL / HTML+CSS


#7

Hi,
Thanks for replying.

Unfortunately your solution didn’t seem to work. Below is the exact text used in the .htaccess, maybe I made a mistake?

I don’t insist on having category name as the first part of my path, initially I just had postname, but the WP codex said that there was a possible problem with only using the postname. It said you may not be able to access pages like:
example.com/folder/

So I tried adding the categoryname to see if that made a difference. I woul actually prefer just postname.

When I tried you changes to the file all pages/links except the index gave a 404.

Should I go back to just postname and add you code?

TIA
Planetphillip

TEXT USED IN .HTACCESS:

BEGIN WordPress

RewriteEngine On RewriteBase / # no substitution in order to access real files or directories RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d [OR] # no substitution in order to access site statistics RewriteCond %{REQUEST_URI} ^/stats/(.*)$ [OR] # no substitution in order to access default Unauthorized error document RewriteCond %{REQUEST_URI} ^/failed_auth.html$ [OR] # skip substitution, see RewriteCond directives above RewriteRule ^.*$ - [S=54] RewriteRule ^(links)/trackback/?$ /index.php?pagename=$1&tb=1 [QSA,L] RewriteRule ^(links)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L] RewriteRule ^(links)/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L] RewriteRule ^(links)/page/?([0-9]{1,})/?$ /index.php?pagename=$1&paged=$2 [QSA,L] RewriteRule ^(links)/?([0-9]+)?/?$ /index.php?pagename=$1&page=$2 [QSA,L] RewriteRule ^(always-looking-for-2)/trackback/?$ /index.php?pagename=$1&tb=1 [QSA,L] RewriteRule ^(always-looking-for-2)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L] RewriteRule ^(always-looking-for-2)/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L] RewriteRule ^(always-looking-for-2)/page/?([0-9]{1,})/?$ /index.php?pagename=$1&paged=$2 [QSA,L] RewriteRule ^(always-looking-for-2)/?([0-9]+)?/?$ /index.php?pagename=$1&page=$2 [QSA,L] RewriteRule ^(about)/trackback/?$ /index.php?pagename=$1&tb=1 [QSA,L] RewriteRule ^(about)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L] RewriteRule ^(about)/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L] RewriteRule ^(about)/page/?([0-9]{1,})/?$ /index.php?pagename=$1&paged=$2 [QSA,L] RewriteRule ^(about)/?([0-9]+)?/?$ /index.php?pagename=$1&page=$2 [QSA,L] RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L] RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L] RewriteRule ^page/?([0-9]{1,})/?$ /index.php?&paged=$1 [QSA,L] RewriteRule ^comments/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1&withcomments=1 [QSA,L] RewriteRule ^comments/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1&withcomments=1 [QSA,L] RewriteRule ^comments/page/?([0-9]{1,})/?$ /index.php?&paged=$1 [QSA,L] RewriteRule ^search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?s=$1&feed=$2 [QSA,L] RewriteRule ^search/(.+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?s=$1&feed=$2 [QSA,L] RewriteRule ^search/(.+)/page/?([0-9]{1,})/?$ /index.php?s=$1&paged=$2 [QSA,L] RewriteRule ^search/(.+)/?$ /index.php?s=$1 [QSA,L] RewriteRule ^category/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&feed=$2 [QSA,L] RewriteRule ^category/(.+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&feed=$2 [QSA,L] RewriteRule ^category/(.+)/page/?([0-9]{1,})/?$ /index.php?category_name=$1&paged=$2 [QSA,L] RewriteRule ^category/(.+)/?$ /index.php?category_name=$1 [QSA,L] RewriteRule ^author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?author_name=$1&feed=$2 [QSA,L] RewriteRule ^author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?author_name=$1&feed=$2 [QSA,L] RewriteRule ^author/([^/]+)/page/?([0-9]{1,})/?$ /index.php?author_name=$1&paged=$2 [QSA,L] RewriteRule ^author/([^/]+)/?$ /index.php?author_name=$1 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&day=$3&feed=$4 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&day=$3&feed=$4 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /index.php?year=$1&monthnum=$2&day=$3&paged=$4 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&day=$3 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&feed=$3 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&feed=$3 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /index.php?year=$1&monthnum=$2&paged=$3 [QSA,L] RewriteRule ^([0-9]{4})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2 [QSA,L] RewriteRule ^([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&feed=$2 [QSA,L] RewriteRule ^([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&feed=$2 [QSA,L] RewriteRule ^([0-9]{4})/page/?([0-9]{1,})/?$ /index.php?year=$1&paged=$2 [QSA,L] RewriteRule ^([0-9]{4})/?$ /index.php?year=$1 [QSA,L] RewriteRule ^(.+)/([^/]+)/trackback/?$ /index.php?category_name=$1&name=$2&tb=1 [QSA,L] RewriteRule ^(.+)/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&name=$2&feed=$3 [QSA,L] RewriteRule ^(.+)/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&name=$2&feed=$3 [QSA,L] RewriteRule ^(.+)/([^/]+)/page/?([0-9]{1,})/?$ /index.php?category_name=$1&name=$2&paged=$3 [QSA,L] RewriteRule ^(.+)/([^/]+)/?([0-9]+)?/?$ /index.php?category_name=$1&name=$2&page=$3 [QSA,L] RewriteRule ^(.+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&feed=$2 [QSA,L] RewriteRule ^(.+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&feed=$2 [QSA,L] RewriteRule ^(.+)/page/?([0-9]{1,})/?$ /index.php?category_name=$1&paged=$2 [QSA,L] RewriteRule ^(.+)/?$ /index.php?category_name=$1 [QSA,L]

END WordPress

Phillip
http://www.planetphillip.com/
Commentary and Analysis of Sci-Fi Single Player First Person Shooters


#8

OK, you made a mistake in using category in the permalink structure. Re-read the Codex page again, you forgot the other caveats they mention besides postname.
http://codex.wordpress.org/Using_Permalinks

Basically it is not a good idea to using postname, category or author as the first part of the path to avoid conflicts with accessing non-blog pages. The blog part have to intercept so it can see if the word is a post name, author or category and there is no way for it to say “there is no such category, trying accessing it as something else instead” The same applies for the other tags, but you’re less likely to have the same conflict since they use numbers instead of words.

:cool: Perl / MySQL / HTML CSS


#9

Thank You for your help.

By changing the permalink structure as you suggested made eveything work. There was no need for me to add anything into the .htaccess.

Thanks again.

Phillip
http://www.planetphillip.com/
Commentary and Analysis of Sci-Fi Single Player First Person Shooters


#10

We get a fair bit of support about this and the change to .htaccess was something I came up with. Apparently it doesn’t actually work completely, though!

If one of you guys wants to post this information to the DreamHost Wiki, that would be great. I’ll pass the information along to our support team, as well.

  • Dallas
  • DreamHost Head Honcho/Founder

#11

so, are you saying that if you use friendly urls, stats don’t work?


#12

Thanks to Brianarn over at the wordpress forums, this fix worked for me… placing the stats fix above the wordpress one so that it wouldn’t be modified if the permalink structure, etc are change. BTW, I am using /category/ in my permalink structure and I am now able to access the stats

WP Fix

RewriteEngine On RewriteBase / RewriteCond %{REQUEST_URI} ^/stats/(.*)$ [OR] RewriteCond %{REQUEST_URI} ^/failed_auth.html$ RewriteRule ^.*$ - [L]

BEGIN WordPress

RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php

END WordPress