views:

71

answers:

3

Dear all,

I need some help about rewrite_mode,

this is my wordpress address:

http://localhost/my_v2010/restaurants?m=display_Add

base_url: http://localhost/my_v2010/

post_name:restaurant

query string:?m=display_Add

I would like to use rewrite mode, let user just type

http://localhost/my_v2010/restaurants/display_Add

any clue how to write in .htaccess?

I tried

RewriteEngine On
RewriteBase /my_v2010/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /my_v2010/index.php [L]
RewriteRule ^restaurants/([^/]+)/?$ restaurants?m=$1 [L]

but no luck, it didn't show what http://localhost/my_v2010/restaurants?m=display_Add had shown. So I need your guys help. Thanks a lot!

A: 

try reordering you rules. the [L] tag means it is the last rule that gets run.

Josh
can you please show me the .htaccess how to reorder is the best way, I know [L] means the last rule. But I try to swap the last 2 rows, but no luck with that.
Shiro
you need to move it above the RewriteCond
Josh
A: 

I change to

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /my_v2010/
RewriteRule ^restaurants/([^/]+)/?$ restaurants?m=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /my_v2010/index.php [L]
</IfModule>
# END WordPress

it become 404 not found.

so what I think is http://localhost/my_v2010/restaurants/display_Add didn't end up like http://localhost/my_v2010/restaurants?m=display_Add

I still able to get http://localhost/my_v2010/restaurants?m=display_Add run, but not http://localhost/my_v2010/restaurants/display_Add

Shiro
+1  A: 

Force the custom URL redirection back to the browser so WordPress can understand it:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /my_v2010/
RewriteRule ^restaurants/([^/]+)/?$ restaurants?m=$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /my_v2010/index.php [L]
</IfModule>
# END WordPress

That will rewrite the request to the expected format and then come through again, piping it through the index.php page for WordPress.

Cryo
ya, this is wordpress original .htaccess, I try to modify it when user access PAGE, the system allow passing query string, but I would like the URL look more user friendly, compare ?m=display_Add, /display_Add would be more nicely to see it.
Shiro
Did my fix not work for you?
Cryo
unfortunately, it didn't work for me :( It redirect to workpress 404, actually the "restaurants" just a pages, I would like to more flexible, not only able do with restaurants, but other page, which needed ?m= <- as query string as well.
Shiro
I updated my answer to add the QSA flag on the rewrite rule, that should append the $m variable when passing in to WordPress. Let me know if that helps you.
Cryo
after I added QSA also didn't make much different, are you familiar with wordpress? maybe your guys can download the latest version, and play around it. I follow this website tutorial to learn rewrite mod http://www.elated.com/articles/mod-rewrite-tutorial-for-absolute-beginners/, what I try to achieve is Example 2: Creating friendly URLs
Shiro
Alright, you may need to force the redirect back to the browser for WordPress's sake. I've updated my answer to try that approach, let me know if that works for you.
Cryo
thx Cryo, really appreciate your helping, I already updated by using ur code.it work for restaurants/display_Add,it redirect to restaurants?m=display_Add.Can't I get remind restaurants/display_Add there?any approach can get my idea outcome?
Shiro
I tried a number of test approaches on one of my existing WordPress installations without any success, WordPress only seems to respect the actual browser URL. To get your custom URL to work without changing the actual WordPress source I believe this is going to be your only option. Your question hasn't been up that long, someone else may be able to give a solution that I'm not aware of if you leave this open for a few more days.
Cryo
thx so much Cryo for your help. Rewrite Mod really a new area for myself, have to study more to get understand how it work. If no other solution I will keep your solution. Thx a lot! Thumb Up!
Shiro