Live data from Hacker News

Seek geek with expert knowledge in WP3 + Apache2 mod_rewrite

news.ycombinator.com

1–6 of 6 posts

Seek geek with expert knowledge in WP3 + Apache2 mod_rewrite

#1
I am seeking a geek with expert knowledge in WordPress 3.0.1 and Apache2 mod_rewrite syntax (.htaccess) to help me get past a roadblock in deploying my web app (with a WordPress front-end).

I have posted my question on stackoverflow.com ( http://bit.ly/9UeChD ) and wordpress.com ( http://bit.ly/aTSo21 ), but still no joy.

Hoping someone on HN has what it takes to rewrite "http://site.com/app/alpha/beta" to "http://site.com/app/?a=alpha&b=beta" and then let the Wordpress rules route it through index.php to the "app" page, which can pull the parameters from $_GET.

Re: Seek geek with expert knowledge in WP3 + Apache2 mod_rewrite

#3

Off the top of my head, maybe adding RewriteRule ^app/([^/]+)/([^/]+) app/?a=$1&b=&2 [QSA,L] before the last rewrite rule?

I tried that, and it gets me part way there, but the internals of the WordPress index.php come into play to prevent this being a solution.

1. WordPress wants the "Page" name to come last, so I followed your suggestion, but with "app" moved to the end. Same idea as your rule, but rearranged. See .htaccess appended below.

2. The REQUEST_URI is "alpha/beta/app", and the QUERY_STRING "p1=alpha&p2=beta", ...

but the WordPress index.php comes into play and seems to do a REDIRECT (so my app never gets a chance to run)

so that REQUEST_URI becomes "app" and QUERY_STRING is empty. My app code runs, but now it is too late; the parameters are gone.

Any further suggestions?

  # .htaccess
  
  
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^([^/]+)/([^/]+)/app$ /app/?p1=$1&p2=$2 [QSA,L]
  
  
  # BEGIN WordPress
  
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  
  
  # END WordPress

Re: Seek geek with expert knowledge in WP3 + Apache2 mod_rewrite

#4
post #3

Off the top of my head, maybe adding RewriteRule ^app/([^/]+)/([^/]+) app/?a=$1&b=&2 [QSA,L] before the last rewrite rule?

I tried that, and it gets me part way there, but the internals of the WordPress index.php come into play to prevent this being a solution. 1. WordPress wants the "Page" name to come last, so I followed your suggestion, but with "app" moved to the end. Same idea as your rule, but rearranged. See .htaccess appended below. 2. The REQUEST_URI is "alpha/beta/app", and the QUERY_STRING "p1=alpha&p2=beta", ... but the WordP…

What do you mean by "Page name"?

Also, I should go ahead and tell you that I know very very little about Wordpress, and how it handles things. Would it be feasible to move this part of your project away from Wordpress?

Re: Seek geek with expert knowledge in WP3 + Apache2 mod_rewrite

#5
post #3

Earlier quoted context omitted.

I tried that, and it gets me part way there, but the internals of the WordPress index.php come into play to prevent this being a solution. 1. WordPress wants the "Page" name to come last, so I followed your suggestion, but with "app" moved to the end. Same idea as your rule, but rearranged. See .htaccess appended below. 2. The REQUEST_URI is "alpha/beta/app", and the QUERY_STRING "p1=alpha&p2=beta", ... but the WordP…

What do you mean by "Page name"? Also, I should go ahead and tell you that I know very very little about Wordpress, and how it handles things. Would it be feasible to move this part of your project away from Wordpress?

In WordPress, ... in addition to your (blog) "Posts" you can create a "Page". The typical example would be an "About" page.

In my case, I created a paged called "app". What is nice about this is I can use WordPress as a content management system, I can change Themes easily, etc. ... but embedded inside the page I can put vanilla PHP code.

Re: Seek geek with expert knowledge in WP3 + Apache2 mod_rewrite

#6

Off the top of my head, maybe adding RewriteRule ^app/([^/]+)/([^/]+) app/?a=$1&b=&2 [QSA,L] before the last rewrite rule?

After following your suggestion, I dove into the WordPress index.php and followed the flow for how it routes you to a particular page.

I found that I can insert my own PHP code to scrutinize the REQUEST_URI, QUERY_STRING, etc, so I can pull out the parameters needed for my app, and then edit the REQUEST_URI so WordPress is none the wiser, ... and simply displays the proper page. ... then my app code gets invoked, ... plus it has access to my parameters. Solution found.