Forum Moderators: phranque

Message Too Old, No Replies

Modrewrite of wp conflict with other RewriteRule on file .htaccess

         

Dave83x

7:06 pm on Jan 21, 2010 (gmt 0)

10+ Year Member



Hello everyone.
I have a problem with generating modrewrite wordpress. Unfortunately wordpress RewriteRule conflict with other RewriteRule on site. example with this:

RewriteUrl ^schede/([^/]*)/([^/]*).html lista_schede.php?marca_id=$1_$2

Perhaps rewriterules of wordpress are too broad and in conflict with all the RewriteRule I use the site for other scripts outside the wordpress platform.

how can I solve this problem?

all the pages that I try to open (which have their RewriteRule containing the file. htaccess) are sent to the 404 error page of wp.

Yes, but it not work.
My file .htaccess is this:

# -FrontPage-

IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName [site.com...]
AuthUserFile /home/site/site.com/htdocs/_vti_pvt/service.pwd
AuthGroupFile /home/site/site.com/htdocs/_vti_pvt/service.grp

php_value session.save_path "/tmp"

RewriteEngine On
RewriteRule ^cellulare/([^/]+)/([^/]+)_([^/]+).html show_scheda.php?mod_rewrite=1&scheda_id=$1_$2_$3
RewriteRule ^cellulari/([^/]+)/([^/]+).html lista_schede.php?marca_id=$1_$2

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

Please help me! :)
thank you

severinp73

7:36 pm on Apr 23, 2010 (gmt 0)

10+ Year Member



Hi there!

I am having an issue with my .htaccess and have searched for a solution for the problem without success. I only started to get involved with MyBB recently and I am not a code expert. First, let me explain my setup.

I have a wordpress blog in the root directory www.domain.com . Other than that, I have another wordpress blog under www.domain.com/de
MyBB is installted under www.domain.com/forum . My host is 1and1.com Linux and mod_rewrite is supported.

Since I wanted to enable SEO friendly titles for the MyBB forum, I followed the Wiki guide [wiki.mybboard.net...] After renaming the htaccess.txt file to .htaccess and turning on the "Enable search engine friendly URLs?" in Server and Optimization Options, I get a 404 server
error.

Now I was wondering whether that had anything to do with the fact, that I already have a .htaccess file in my root directory in addition to the .htaccess file in the forum directory.

the .htaccess in my root directory looks like this:

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

Options All -Indexes

AddType x-mapp-php5 .php

AddHandler x-mapp-php5 .php

# END WordPress




the .htaccess file in my forum directory looks like this:

Options -MultiViews +FollowSymlinks -Indexes

#
# If mod_security is enabled, attempt to disable it.
# - Note, this will work on the majority of hosts but on
# MediaTemple, it is known to cause random Internal Server
# errors. For MediaTemple, please remove the block below
#
<IfModule mod_security.c>
# Turn off mod_security filtering.
SecFilterEngine Off

# The below probably isn't needed, but better safe than sorry.
SecFilterScanPOST Off
</IfModule>

#
# MyBB "search engine friendly" URL rewrites
# - Note, for these to work with MyBB please make sure you have
# the setting enabled in the Admin CP and you have this file
# named .htaccess
#
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^forum-([0-9]+)\.html$ forumdisplay.php?fid=$1 [L,QSA]
RewriteRule ^forum-([0-9]+)-page-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2 [L,QSA]

RewriteRule ^thread-([0-9]+)\.html$ showthread.php?tid=$1 [L,QSA]
RewriteRule ^thread-([0-9]+)-page-([0-9]+)\.html$ showthread.php?tid=$1&page=$2 [L,QSA]
RewriteRule ^thread-([0-9]+)-lastpost\.html$ showthread.php?tid=$1&action=lastpost [L,QSA]
RewriteRule ^thread-([0-9]+)-nextnewest\.html$ showthread.php?tid=$1&action=nextnewest [L,QSA]
RewriteRule ^thread-([0-9]+)-nextoldest\.html$ showthread.php?tid=$1&action=nextoldest [L,QSA]
RewriteRule ^thread-([0-9]+)-newpost\.html$ showthread.php?tid=$1&action=newpost [L,QSA]
RewriteRule ^thread-([0-9]+)-post-([0-9]+)\.html$ showthread.php?tid=$1&pid=$2 [L,QSA]

RewriteRule ^post-([0-9]+)\.html$ showthread.php?pid=$1 [L,QSA]

RewriteRule ^announcement-([0-9]+)\.html$ announcements.php?aid=$1 [L,QSA]

RewriteRule ^user-([0-9]+)\.html$ member.php?action=profile&uid=$1 [L,QSA]

RewriteRule ^calendar-([0-9]+)\.html$ calendar.php?calendar=$1 [L,QSA]
RewriteRule ^calendar-([0-9]+)-year-([0-9]+)\.html$ calendar.php?action=yearview&calendar=$1&year=$2 [L,QSA]
RewriteRule ^calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)\.html$ calendar.php?calendar=$1&year=$2&month=$3 [L,QSA]
RewriteRule ^calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)-day-([0-9]+)\.html$ calendar.php?action=dayview&calendar=$1&year=$2&month=$3&day=$4 [L,QSA]
RewriteRule ^calendar-([0-9]+)-week-(n?[0-9]+)\.html$ calendar.php?action=weekview&calendar=$1&week=$2 [L,QSA]

RewriteRule ^event-([0-9]+)\.html$ calendar.php?action=event&eid=$1 [L,QSA]

<IfModule mod_env.c>
SetEnv SEO_SUPPORT 1
</IfModule>
</IfModule>

#
# If Apache is compiled with built in mod_deflade/GZIP support
# then GZIP Javascript, CSS, HTML and XML so they're sent to
# the client faster.
#
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/x-javascript text/css text/html text/xml
</IfModule>


Once this issue is fixed I want to install the SEO Google Plugin for MyBB.

Any help is greatly appreciated.

Thanks in advance!

jdMorgan

8:04 pm on Apr 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will need to exclude the "forum" URL-path from the rule in your top-level file using a negative-match RewriteCond.

I suggest that you also exclude the WP /index.php URL-path, and all URL-paths ending in .gif, .jpg, .jpeg, .png, .ico, .css, .js, .pdf, and any other filetypes which are not generated by WP or its plug-ins, this in order to avoid wasting massive server resources checking the filesystem for file- and directory-exists.

This latter subject has been previously covered here in depth, and a site search should turn up the related threads.

The same performance tweak is suggested for the primitive .htaccess code provided by Joomla and any other apps like WP that relies solely on file- and directory-exists checks. There's no reason to check to see if "index.php" exists once you've already rewritten to it, and if the app cannot produce a particular filetype, there's no use in passing the request to it in the first place. And in both cases it would be a waste of time to check to see if it exists first... Not to mention betaing your hard drive to death checking every single requested URL to see if it resolves to an existing file or directory... This minor tweak will double the performance of the rule -- at a minimum, and faster page loads can actually be noticed on some sites.

Jim

severinp73

8:54 pm on Apr 23, 2010 (gmt 0)

10+ Year Member



Hi Jim!

First of all thanks for your instant reply!

Since I am a novice, I do not know exactly how to make those RewriteCond modifications properly. Can you give me an example on how to do that exactly?

Let's say my forum domain is domain.com/forum - what does the code need to look like and in what line in the top level .htaccess would you put it.

In the meantime, I added RewriteBase /forum/ to the lower level .htaccess and it is working fine. But if you still think, I ought to make the changes to the top-level file in order to gain speed, I am more than happy to do that?

Thanks in advance!

g1smd

12:20 am on Apr 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Nice to see that the forum software still includes those "nextnewest" and "nextoldest" links creating multiple Duplicate Content issues galore. Its more than four years since I first raised the issue and the dumb as rocks design still prevails? Words fail me.

jdMorgan

4:35 pm on Apr 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd suggest:

Options All -Indexes
#
AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php
#
RewriteEngine On
#
# BEGIN WordPress (modified)
RewriteBase /
#
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{REQUEST_URI} !^/forums/
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|ico|css|js|swf|flv|wmv|avi|mp3)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

The first RewriteCond prevents re-execution after the rewrite to index.php has already been invoked.

The second RewriteCond prevents rule execution if the /forums/ subdirectory or anything in it is requested.

The third RewriteCond prevents rule execution if any filetype not generated (created) by WP scripts is requested. Adjust to suit your site, and put the filetypes in most-frequently-requested-first order.

It is not critical to list all possible filetypes, only those requested most often. Get rid of extensions that you don't use on your site, and add only those that get requested with all or most page-loads. You could add *absolutely all* non-WP-created filetypes, but eventually you will reach a point of diminishing returns. Certainly, excluding .gif, .jpg, and .jpeg files as shown provides the largest benefit, since most pages include multiple images...

The pattern-anchoring differs in each case. That is intentional (and critical to proper function).

By adding these new exclusions ahead of the previously-existing RewriteConds, you avoid two totally-unnecessary calls to the operating system to go check the filesystem (and possibly the physical disk itself) to see if the requested object resolves to an existing file or directory, thus speeding up your server and increasing the lifespan of your server's hard drive.

I removed the <IfModule> container because its only function is to cause the mod_rewrite code to fail silently on servers where mod_rewrite is not available. While this may be good for WP's support department, it is certainly not what the average Webmaster would want.

Jim

severinp73

4:21 pm on Apr 25, 2010 (gmt 0)

10+ Year Member



Thank you very much Jim,

this is what my .htaccess looks like now.
Options All -Indexes
#
AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php
#
RewriteEngine On
#
# BEGIN WordPress (modified)
RewriteBase /
#
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{REQUEST_URI} !^/forum/
RewriteCond %{REQUEST_URI} !\.(gif|jpeg|png|ico)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress


And it works just fine

jdMorgan

5:55 pm on Apr 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note that the subpattern "jpe?g" was intended to match both "jpg" and "jpeg". Having deleted the question mark, your subpattern will now match only "jpeg".

I'm also surprised that you deleted the "css" subpattern, as it's likely that WP uses --but does not generate-- CSS files for its templates. So there's no use running the 'exists' checks against these files and they should generally be excluded along with the image files, etc. listed in my example.

Jim
This 37 message thread spans 2 pages: 37