开发者

How to modify .htaccess for web app (in combination with WordPress 3.0.1)

My question is about .htaccess

I am using WordPress 3.0.1 as the front end of my web application. I want most HTTP accesses to follow the normal WordPress flow.

However, I have created a special "Page" in WordPress that has embedded PHP code that powers my web app.

URL's of this form "http://site.com/app/" already go to the correct page.

URL's of this form "http://site.com/app/?a=alpha&b=beta" go to the same page, and pass parameters to my web app. This is correct, but the URL looks ugly.

Here is my question:

I want nice looking URLs of thi开发者_Python百科s format:

http://site.com/app/alpha/beta

to be rewritten this way ->

http://site.com/app/?a=alpha&b=beta

I have tried adding various things in .htaccess, but I can't get it to work. I typically end up with a WordPress 404 page being displayed.

Here is the .htaccess file that was created when installing WordPress 3.0.1

# .htaccess
# 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

I am sure there must be lots of folks using WordPress as a front end for their web app, and others with expertise in .htaccess syntax. Any answers or pointers to solutions would be appreciated.

thanks in advance,

David Jones

dxjones@gmail.com

http://dxjones.com


David, don't know the answer for sure, but here's a thought.

You can use plugins like this: http://wordpress.org/extend/plugins/exec-php/

It let's you execute code from within pages or posts.

If you look into the WP documentation, you could easily tie another PHP app into WP.


Firstly, to use rewrite rules in .htaccess, two things are required:

Options +FollowSymlinks
RewriteEngine on

Then this rule will do what you describe:

RewriteRule ^app/([^/]+)/([^/]+) /app/?a=$1&b=$2 [L]
  • FYI ... [^/] matches any character except for "/"
  • and the [L] at the end will make this rewrite invisible to the user --- it's only passed to your application.

UPDATE

To make visitors using old links automatically redirect to the nicer URL (and possibly improve search engine mapping of webapp pages), add an additional rule --- like this one:

 RewriteCond %{QUERY_STRING} a=([^&]+)&b=([^&]+)
 RewriteRule ^app/?$ /app/%1/%2  [R=301]

The rule above turns the a and b parameters into your nice URL -- however, it would not pass on additional query parameters. (i.e. site.com/app?a=me&b=you&tag=zebra would redirect, but 'tag' parameter would be discarded in the process.) Here is a variation that allows for additional parameters:

 RewriteCond %{QUERY_STRING} (^|.*&)a=([^&]+)&b=([^&]+)(&.*|$)
 RewriteRule ^app/?$ /app/%2/%3?%1%4  [R=302]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜