Forum Moderators: phranque

Message Too Old, No Replies

How do I handle multiple rewrite commands in .htaccess

         

TexasExplorer

3:28 am on Jan 31, 2011 (gmt 0)

10+ Year Member



Hi all. It's been so long since I've been here I couldn't even remember my logins, lol. But I have a question I'm sure you guys can help me with so here goes...

I have a shopping cart which requires one rewrite, and I have Wordpress that needs a rewrite rule for path names, and I have a rewrite rule that directs mydomain.com to www.mydomain.com.

The problem is, when the Wordpress code is there, the shopping cart rewrite doesn't work. Is there a way I can do this and still be able to keep all the rewrite rules?

Thanks in advance =).

RewriteEngine On

RewriteCond %{REQUEST_URI} !-s
RewriteRule ^page/(.*) /Merchant2/merchant.mvc?page=$1
php_flag register_globals on

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC]
RewriteRule (.*) [mydomain.com...] [R=301,L]
</IfModule>

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

g1smd

8:04 am on Jan 31, 2011 (gmt 0)

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



You have three RewriteEngine and two RewriteBase directives. There should only be one RewriteEngine directive. The RewriteBase directive isn't needed at all.

Within your code, the 301 redirect must be listed first, before any internal rewrites. The ifmodule tags are not needed at all.

For the rewrites, the pattern for WP must be able to match WP URL requests, and the pattern for the cart must be able to match cart URL requests. The easist and most efficient way is for these to have a separate /blog/ and /cart/ (or what ever names you want) folder name.

Your WP code is very inefficient. There's a thread in this forum with completely revised rules for WP that you might like to try.

jdMorgan

3:37 am on Feb 1, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



General rule: External redirects first, internal rewrites after. Rules in each group ordered from most-specific to least-specific patterns and conditions. Access controls, if any, should precede the redirects: No use wasting time redirecting unwelcome clients...


php_flag register_globals on
#
RewriteEngine On
RewriteBase /
#
RewriteCond %{HTTP_HOST} !^(www\.mydomain\.com)?$
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
#
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^page/(.*) /Merchant2/merchant.mvc?page=$1 [L]
#
# BEGIN modified WordPress
RewriteCond $1 !(\.(gif|jpe?g|png|ico|css|js|xml|txt)|^index\.php)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php [L]
# END modified WordPress

As coded, all non-blank, non-canonical-hostname requests will be externally redirected to the canonical hostname. For now-canonical-hostname requests, requested URL-paths which start with "page/" and do not resolve to files larger than zero bytes will be rewritten to Miva. Those requests not rewritten to Miva will be further tested, and those which are not in the list of exclusions and which further do not resolve to existing files or directories on the disk will be rewritten to WP.

The list of exclusions added to the WP code can markedly improve your site's speed under heavy load and make your disk last longer. by eliminating many, many unnecessary filesystem checks. Remove at your own risk.

Jim

g1smd

8:36 am on Feb 1, 2011 (gmt 0)

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




... ..