.htaccess sef pagination link to query string - wordpress

I have a url structure as xxxx.com/blog/page/1. But pagination gives 404. I need to rewrite it with .htaccess as xxxx.com/blog?page=1. Can you help me?
RewriteRule ^blog/page/([0-9]+)$ blog?page=$1 [R=302,L]
i try this rule in htaccess

Related

301 Redirect not working (WordPress) - [ Probler with ?m=1 in URL ]

I have very weird problem.
My WordPress site gets traffic to the same page with different additional parameters.
Example:
mysite.com/page1.html?m=1
mysite.com/page1.html
It is the same page, but ?m=1 makes WP show 404 error page.
I tried 301 redirect like this (in actual HTACCESS file i also use http:// but here I cannot):
Redirect 301 /page1.html?m=1 mysite.com/page1.html
But this does not do anything.
Traffic comes from google, so I cannot change this URL structure - I have to work with what I got ... So how I fix this???
It could be either WP or HTACCESS problem ... I searched and cannot find anything - i get results for M1 rifle :(
Please help - this is a live site
You can't match against the query string in mod_alias's Redirect or RedirectMatch. You need to use mod_rewrite's %{QUERY_STRING} or %{THE_REQUEST} variables. Try:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^m=1$
RewriteRule ^(.*)$ /$1? [L,R=301]
This will redirect any request that has the "m=1" query string and remove it.
.htaccess
RewriteEngine On
RedirectMatch 301 ^/page1.html?m=1$ /page1.html
Try that see also this answer .htaccess 301 redirect of single page

Change URL name with mod rewrite on htaccess?

I want to redirect the some urls to others using the htaccess file. I want to show
http://test.com/news/david-highlights-unsung-community-hero/
when someone open the url
http://test.com/index.php?process=views/article.php&articleId=44102
using the htaccess file. Please let me know how I can rewrite the rule for such urls in htaccess file.
If you want to redirect that exact URL using htaccess, you can do this.
redirect /index.php?process=views/article.php&articleId=44102 http://test.com/news/david-highlights-unsung-community-hero/
For more information, visit: http://webmaster.iu.edu/tools-and-guides/maintenance/redirect-htaccess.phtml
*Please let me know how I can rewrite the rule for such urls in htaccess file.
In your .htaccess file add:
`Redirect 301 /news/david-highlights-unsung-community-hero/ http://test.com/index.php?process=views/article.php&articleId=44102`
OR
`Redirect 302 /news/david-highlights-unsung-community-hero/ http://test.com/index.php?process=views/article.php&articleId=44102`
302 redirects are good if you will do SEO for your site later, 301 redirects are permanent, Or you can use ' preety link ' wordpress plugin to get this done from wordpress admin panel.
put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^process=views/article\.php&articleId=44102$ [NC]
RewriteRule ^index\.php$ /david-highlights-unsung-community-hero/? [L,NC,R=301]

RewriteRule gives 404

I have troubles with mod_rewrite.
I have wordpress site located in 'wp' directory. It is accessible as http://localhost/wp/
There is page http://localhost/wp/sample-page/ on the site.
I want to make this page open with url http://localhost/wp/sample-page-2/ without redirect.
Here is what in .htaccess file:
RewriteEngine On
RewriteBase /wp/
RewriteRule ^sample-page-2/$ sample-page/ [L]
But I'm getting 404 error.
Could somebody explain me what I'm doing wrong?
Thanks in advance.
UPD:
#soju: Well, "sample-page-2" - is just example
It is not a page/post in worpress sence.
Actually I tried to add one section to the url. E.g. http://localhost/wp/sample-page/section/. And this rule RewriteRule ^sample-page/section/$ sample-page/ [L] didn't work. Then I decided to "simpliyfy" url("sample-page-2" instead of "sample-page/section") - no success.
UPD2
BTW, redirect RewriteRule ^sample-page-2/$ sample-page/ [R=301,L] works
I suppose wordpress rewrite rules are after your own rule, so you should remove [L] option to let wordpress handle sample-page url
EDIT about UPD2 : Well, it works with a 301 redirection, but you said you don't want redirection ?
You can add a filter on rewrite_rules_array to make your own rewrite rule, take a look at example on codex : http://codex.wordpress.org/Class_Reference/WP_Rewrite#Examples

How to URL rewrite a moved site from wordpress?

I moved my site from wordpress to another platform. I tried to rewrite the old urls without success.
previously I had url structures similar to examples down below...
domain.com/category/post-name.html
domain.com/category/page-name
domain.com/category/post-2010-name.html
domain.com/2011/02/16/post-name.html
domain.com/2011/02/16/page-name
as you can see above sometimes the postname had a number to it. Also, pages and posts were listed with dates.
the new url structure is...
domain.com/brand-new-section/blog/
so old url...
domain.com/mobile-phones/new-iphone-5-maps-issue.html
should map to...
domain.com/brand-new-section/blog/mobile-phones/new-iphone-5-maps-issue
so, I did the url rewrite for dates...
RewriteRule ^/[0-9]+/[0-9]+/[0-9]+/(.*)?$ domain.com/brand-new-section/blog/$1 [R=301,NC,L]
Any suggestions?
how can I combine the above url rewrite with other rewrite rules such as... domain.com/category/post-name.html
domain.com/category/post-2010-name.html
tried...
RewriteRule ^/[0-9]+/[0-9]+/[0-9]+/(.*)?$ http://www.domain.com/brand-new-section/blog/$1[R]
RewriteCond %{REQUEST_URI} ^/[a-zA-z]+/[a-zA-z]+/(.*)?\.html$
RewriteRule ^/[a-zA-z]+/[a-zA-z]+/(.*)?\.html$ http://www.domain.com/brand-new-section/blog/$1 [R=301,NC,L]
no success.
thank you.

.htaccess permanent redirect of query string to directory

I'm trying to use .htaccess redirect to solve my slider post issue on my wordpress site.
My current "slider post" URL is as follow leading to a blank post:
http://mysite.com/?slider=post-slug
I want to redirect to the real post location with an identical "post slug":
http://mysite.com/news/post-slug
How do I set my rewrite rules?
Put this (above whatever wordpress rules you may have) in the htaccess file in your document root:
RewriteEngine On
RewriteCond %{QUERY_STRING} slider=([^&]+)
RewriteRule ^$ /news/%1? [R=301,L]

Resources