Why is this regex redirection not working as expected? - redirect

I am using the Redirection plugin on WordPress to redirect some old permalink structured post links to the new permalink structure.
An example of the old structure: /blog/2022/12/french-toast-bread-pudding-in-a-mug.html
Should redirect to: /french-toast-bread-pudding-in-a-mug
As far as I can tell the following should work: /blog/\d{4}/\d{2}/(.*).html
However it is redirecting to /2022/ in the case of the above URL.

Related

Getting Full HTML Source code in when using WP REST API

Installed WP REST API v2Beta13 on Wordpress version 4.4.2 from here, and also gone through it's documentation.
When trying to use the api via POSTMAN and hitting URL:
http://www.example.com/blog/wp-json/wp/v2/posts as a GET request, whole HTML code of home-page (http://www.example.com/blog/) is returned as response.
In fact any URL is giving the html code of home page.
Expect output should be json formatted data as mentioned in it's documentation.
Permalinks setting in wordpress admin-panel is set to http://example.com/blog/sample-post/

How to correctly change page extensions sitewide not to loose rankings in google

Moved content from php files to content management system. Changed page extensions from .php to without any extension, like: before some-page.php after some-page
All php pages keep at server, but made redirection in each php file, like header('Location:'. basename($_SERVER['PHP_SELF'],'.php') );. I cannot (do not know how to) do it in .htaccess, because in .htaccess is this code
RewriteRule ^([a-zA-Z0-9_-]+)$ show-content.php?$1
DirectoryIndex show-content.php?index
From google webmasters tools removed previous sitemap and added the new sitemap. See that the new sitemap accepted, but no urls included.
All above I did 3-4 days before. And today see that website dropped down in search results (some pages can not find at all in first pages).
Trying to understand what I did wrong.
Seems the first thing is wrong redirection code. Changed to header('Location:'. basename($_SERVER['PHP_SELF'],'.php'), true, 301 );. Is such code ok?
What else I did wrong?
You definitely need to do a 301 redirect from the old URL (with the extension) to the new URL (without the extension) as this tells Google the page has moved to a new location and you want all links and other SEO goodness (like rankings) need to be "transferred" to the new URL.
You can do the 301 redirect any way you want so using PHP's header() is fine as long as you are redirecting to the right page. Your example should work fine.

Creating a page on CMS

For example:
I create a page on Joomla or Wordpress and then save it.
I create an entry in the menu that points to the new page.
When I select the new entry in the menu the page opens on the browser.
The URL that appears points to a file that doesn't exist on the server.
What is the mechanism that is used by a CMS like Joomla or wordpress to accomplish this?
This is typically done with a URL rewriting module that runs on the web server (mod_rewrite for Apache or URL Rewrite for IIS on Windows). It will rewrite a request URL like /blog/article-title to something like /index.php/blog/article-title or /index.php?q=blog/article-title before the website code even sees the request. Then, the code in index.php extracts the rest of the path and determines which content to serve based on that.
For Wordpress, see http://codex.wordpress.org/Using_Permalinks for some info about how the rewrites are set up.

URL Rewriting and Facebook link information retrieval

I am developing a website and I want to integrate it with Facebook, allowing users to share the pages of my website in their FB walls. My problem is explained in the following lines and my question is at the end.
I am using the following URL rewriting rule in my .htaccess file:
RewriteRule ^([a-zA-Z0-9_-]+)\/?([a-zA-Z0-9_-]+)\/?$ index.php?p1=$1&p2=$2
That means it will rewrite anything like: http://address/parameter1/parameter2 as http://address/index.php?p1=parameter1&p2=parameter2.
When I post http://address/parameter1/parameter2 on FB, it will only show the rewritten URL under that URL.
I posted http://address/index.php?p1=parameter1&p2=parameter2 on FB, and it will show the information I want it to show, the ones I have put in the meta tags.
I tried debugging http://address/parameter1/parameter2 on the FB debugger (http://developers.facebook.com/tools/debug), I will get the error:
"The page at ... could not be reached because the server returned status code 400."
Is there any way I can correct that? That is, actually making the dynamic link behave like a static link, and making that transparent to anyone who links it?
Edit:
This change in the rewrite rule should solve the problem:
RewriteRule ^([a-z0-9_-]+)/?([a-z0-9_-]+)/?$ index.php?p1$1&p2=$2 [L,NC]
I also changed the redirects in PHP that I was doing.
And that solved my problem.
I have similar issue to yours, except I manage url rewriting with php dynamically.
I am currently a web host that do not allow url rewriting through htaccess (free.fr)
dynamic standard url is handled properly. But not rewrited url.
How would you get rid of this, considering header status code?
What I could do is doing a redirect instead of include script which produce html output code.
Just have to tell the handler to switch between include and redirect, thanks to a special added param in the url.
But it's not a pretty solution.

I want to redirect the index.php from a Wordpress site to another URL, and all the other URLs in the WP site separatley

So, here is the problem:
I need to have a redirect from website.ro/ to website.com/
Website.ro is on wordpress.
At the same time, all the sub-links like website.ro/title will be redirected individually to website.com/different_title_same_content
If i do this:
Redirect 301 /index.php http://website.com/
Redirect 301 /title http://website.com/different_title_same_content
What happens is that website.ro is on wordpress, that means that all the sublinks are called through index.php (i think, but not sure) and if i do a redirect on index.php than all the other links will be redirected to the homepage and not to their corresponding innerpage.
Its like setting a master rule when i'm redirecting the index.php.
What i would like to do is redirect index.php to a homepage, and any other variation on its corresponding subpage on the new website.
Can it be done?
EDIT: I have added a little of the code that i have to write:
Redirect 301 /Zuzu newsite/portfolio/cases/doc/47860743/
Redirect 301 /Antena1 newsite/portfolio/cases/doc/47860862/
...and so on for allmost 100 urls. (i had to post here without http and www since i am not allowed here more than 2 urls)
The reason i have to do this is that in the past, many of the links on the oldsite appeared in articles, press, blogs and so on, and i do not want to loose traffic that the old links generated on each page.
At the same time, i want to redirect the homepage to the newsite homepage, but if i do this with:
Redirect 301 / newsite/
it will redirect all the other links to the main page of the newsite and not to its corresponding article.
Its the same if i do Redirect 301 /index.php newsite/
since the old website is on wordpress and i think that all the pages are called through index.php(and some variables)
Also, the urls on the newsite.com are not rewritable as to rename them as the old ones so i can create an automated redirect generally valid.
WHAT IS THERE TO DO?
Look into this it may solve your issue
http://enarion.net/web/htaccess/migrate-domains/
Best of luck!