简体   繁体   中英

Wordpress and mod-rewrite URL to category page

Goal - display proper page for short version of an URL

Htaccess file:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^wholesale/?$ /products-page/wholesale/$1 [NC] # Handle requests for "wholesale"
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

But when I will go to http://www.utatz.com/wholesale it doesn't load content of http://www.utatz.com/products-page/wholesale/

Any clue what I have done improperly?

Thanks

Let me get this straight:

Option 1)
You want to enter the following URL:
yoursite/wholesale/
And be able to see exactly the same as if you were in:
yoursite/products-page/wholesale/

The easiest way to achieve this is to add a page "wholesale" and create a custom template page with a modified loop.

http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates
http://codex.wordpress.org/Function_Reference/query_posts

OR

Option 2)
You want to enter:
yoursite/wholesale/a-product/
And be able to see the equivalent of:
yoursite/products-page/wholesale/a-product/

If this is what you want to achieve, you should focus in adding/modifying WordPress' own RewriteRules, you should avoid the use of .htaccess as you can instruct WP to understand any given permalink structure.

As an introduction, I'd recommend you to check http://www.hongkiat.com/blog/wordpress-url-rewrite/

Do not forget : Every time that you make changes to the permalink structure, go to Settings -> Permalinks and click on Save Changes, otherwise the changes may not apply until you do so.

I'm not sure if this will work using .htaccess, but a rule within WordPress would look like what is shown in the first RewriteRule of the following example:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^wholesale/(.+)/?$ /index.php?category_name=wholesale&name=$1 [NC] # (.+) represents the title of a post with the "wholesale" category
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

When you are using add_rewrite_rule should look a bit like:

add_rewrite_rule('^wholesale/([^/]*)/?','index.php?category_name=wholesale&name=matches[1]','top');

The examples above will only work if (.+) / ([^/]*) represent a post, if it's a custom post type it will not work, since you would have to add the variable representing such custom post type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM