Forum Moderators: phranque

Message Too Old, No Replies

wordpress rewrite

         

icemancast

2:06 pm on Oct 16, 2007 (gmt 0)

10+ Year Member



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

this is in my wordpress index file to rewrite the urls. there is a section on my website certain directory that i do not want to rewrite. how can i go about this.

jdMorgan

2:38 pm on Oct 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Add a RewriteCond based on %{REQUEST_URI} at the top of this rule (before the file-exists checks), specifying the URL-path common to the resources that you don't want rewritten.

Examples:


RewriteCond %{REQUEST_URI} !^/do-not-rewrite-this-subdirectory/

or

RewriteCond %{REQUEST_URI} !\.do-not-rewrite-this-filetype$

Note that due to the part of the URL-path we're examining, the first pattern is start-anchored, while the second is end-anchored. This eliminates the need to add unnecessary ".*" catch-all subpatterns at the end or beginning of the two patterns, respectively.

Jim

[edited by: jdMorgan at 11:23 pm (utc) on Oct. 16, 2007]

icemancast

9:30 pm on Oct 16, 2007 (gmt 0)

10+ Year Member



tried it and it worked but got rid of rewrite for wordpress. where exactly does it go?

jdMorgan

11:24 pm on Oct 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, got in a hurry, and omitted a critical element -- the "!" NOT operator, now corrected in the post above.

Put this new RewriteCond above the other two RewriteConds.

Jim

[edited by: jdMorgan at 11:24 pm (utc) on Oct. 16, 2007]

icemancast

1:50 pm on Oct 17, 2007 (gmt 0)

10+ Year Member



it didn't work

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

i have an index.php file there that i pass queries to it and when i do it takes me to wordpress stuff

index.php?query=something

jdMorgan

3:19 pm on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First, make sure you've completely flushed your browser cache after changing the code. Otherwise, your request for any previously-requested URLs will be served from the local browser cache, and not sent to your server. If the requests are not sent to your server, then your server-side code cannot have any effect.

Then, be aware that only that directory will be excluded from the RewriteRule, and that any HTTP requests for URL-paths which resolve to any other areas of the filesystem will be subject to the rule.

Jim

icemancast

8:59 pm on Oct 17, 2007 (gmt 0)

10+ Year Member



still didn't work. i posted on other forum and they couldn't figure it out either. no worries.

for some reason every time i delete

RewriteRule . /index.php [L]

it works. is there any way to comment a line in htaccess.

jdMorgan

10:33 pm on Oct 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It can't work with the rule deleted, unless you've got some other rule that's also taking on that function.

You can 'comment-out' lines by preceding them with one or more "#" characters. But the problem here is not with the code, but probably with the requirements not being fully-defined (this is rather elementary code), or perhaps with an unexpected side effect/interaction or a server configuration problem.

Make sure that you have spaces between every "}" and any following "!" character -- Posting on this forum deletes those spaces, unless you take steps to prevent it. The code should look exactly like this (comments added):


RewriteEngine on
RewriteBase /
#
# Skip rewrite for "/directory-in-root/" directory
RewriteCond %{REQUEST_URI} !^/directory-in-root/
# IF the requested URL-path does not resolve to an existing file
RewriteCond %{REQUEST_FILENAME} !-f
# AND IF the requested URL-path does not resolve to an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
# THEN rewrite any non-index-page (non-blank) URL-path request to the /index.php file
RewriteRule . /index.php [L]

Having just added the line-by-line comments, it is indicative of a problem that the "directory-exists" check does not already prevent requests for "/directory-in-root/" from being rewritten -- It should. No requested URL-path that resolves to an existing file or directory should be getting rewritten, even without the most recently-added RewriteCond... You may want to ask your host about this if none of the spaces mentioned above are missing.

Jim

[edited by: jdMorgan at 10:34 pm (utc) on Oct. 17, 2007]