Forum Moderators: phranque
I want to redirect all URLs in the form:
/mypage/bla/bla.htm
to
/mypage/?q=bla/bla.htm
to process $_GET['q'] from the page.
So I tried:
<IfModule mod_rewrite.c>
RewriteEngine On
#my try
RewriteCond %{REQUEST_URI} ^/mypage/([^\?\=]+)$
RewriteRule ^mypage/([^\?\=]+)$ mypage/?q=$1 [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
</IfModule>
The outcome is not any internal server error, but 404, because it's loaded the default wordpress "page not found" page with a search box.
I had a look to a similar thread to come up with ideas:
[webmasterworld.com...]
Thanks in advance for any help.
[edited by: Grimmjow at 6:25 pm (utc) on Mar. 4, 2009]
RewriteEngine on
#
# Rewrite mypage/<something>/<otherthing>.htm to /mypage/?q=<something>/<otherthing>.htm
RewriteRule ^mypage/([^/]+/[^.]+\.htm)$ mypage/?q=$1 [L]
#
# Skip all subsequent rules if requested URL resolves to an existing
# file or directory, or if the request is for "mypage/<anything>"
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_URI} ^/mypage/
RewriteRule . - [L]
#
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.+) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.+\.php)$ $2 [L]
RewriteRule . index.php [L]
Note that you could easily drop the ".htm" from the "q=" value before calling the script, simply by moving the closing parenthese ahead of the "\." in the RewriteRule pattern.
Jim
1) Transcription errors, such as changing more than just the name of "mypage" and accidentally deleting or inserting an extra slash or other character.
2) Other code interfering with this code -- either in a directory above this .htaccess file's directory, or in the server config itself.
3) mod_alias, MultiViews (mod_negotiation), or AcceptPathInfo (Apache 2.x only) grabbing the request before mod_rewrite can modify it.
Let me know if my assumptions about the meaning of "mypage" were incorrect.
Jim