I have setup a website with recipes but in the process of migration OLD urls to NEW urls I'm facing issues with.
https://example.com/recipes/cheesy-baked-tacos/
This is my old URL structure and In a wordpress site I need to extract last part of the URL "cheesy-baked-tacos" and handle that in the template I use for recipes page.
Now when i click on the URL it goes to 404 page even though recipes page has setup.
I tried following htaccess rules but have no success
RewriteBase /
RewriteRule ^recipes/(.*)$ index.php?l=$1
Thanks in Advance.
Full htaccess file looks like this
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^recipes/(.*)$ index.php?l=$1
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
you should check your permalink change to starts with id to without query string
dont change htacces file
you just change permalink in new server
https://example.com/recipes/cheesy-baked-tacos/
this is your old url and has permalink set without query string
new url https://example.com/recipes/cheesy-baked-tacos/id=50 just like
thats why your code have error
Managed to fix the issue with 301 Redirect. Here's what i used if it helps someone.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^recipes/(.*)$ recipe/?post_name=$1 [L,R=301,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Related
I've got an issue with my htaccess redirects not working as expected.
The new website I'm working on is using logical slugs, whereas the old site has outdated IDs etc.
Old url for news item: https://mccann-ltd.co.uk/news.php?pID=87
New url for news item: https://mccann-ltd.co.uk/news/achilles-link-up-accredited-qualified-supplier-to-the-uk-rail-industry
I updated the htaccess with these rules:
RewriteCond %{QUERY_STRING} pID=87(.*)$
RewriteRule (.*) /news/achilles-link-up-accredited-qualified-supplier-to-the-uk-rail-industry [R=301,L]
Which worked, however when I switched to the new wordpress setup, these redirects stopped working. Is it something to do with wordpress's rule? i.e.:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Or could it be that I need to include the file name with my rule i.e. adding news.php:
RewriteCond %{QUERY_STRING} news.php?pID=87(.*)$
Any help would be appreciated as I'm unsure how to move forward.
Thanks
I have installed WP at my root directory and moved the CI application that was at the root to a sub-folder called "members." The WP pages are working just fine, but when I try to sign into the CI application, using my log in form on a WP page, I'm getting back a 404 error. I have a feeling this has something to do with routing and WP overriding things but I've been unable to figure this out so far.
.htaccess at root:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(info|info/.*)$
RewriteCond %{REQUEST_URI} !^/(members|members/.*)$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I wanted the info and members controllers in CI to still be accessible from WP.
I can tell the CI page is being hit because I can still redirect the browser by adding a line in the controller, yet when I try to actually post data with the form and look at the Network activity in Chrome, I can see the 404 is coming back on the page I'm posting to.
UPDATE:
Okay, I've been able to isolate this to being a routing issue, the problem is Wordpress is functional, but CodeIgniter isn't. I realize there's no modrewrite rules that apply to the /members/ directory. Here's where I'm at:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(members|members/.*)$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /members
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Any thoughts?
It was a routing issue! I didn't realize I needed to put the Codeigniter specific .htaccess entries at the subfolder where the Codeigniter application resided. Of course it was that simple!
I have a Wordpress website with root located at
http://www.example.com/web
Via htaccess, when I visit that address I would like to see what's on http://www.example.com/web/about-me with the browser still displaying http://www.example.com/web.
Is it possible to achieve this via .htaccess? What I have right now is
BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php [L]
</IfModule>
END WordPress
I tried adding at the bottom
RedirectMatch ^/$ /about-me/
Without any success.
So essentially you have a website which is hosted on a sub-directory of your domain, and you want to rewrite the homepage URL to your about-me page, but without the user seeing the URL change. Your main issue is trying to use a Redirect which will change the displayed URL.
This should do it
RewriteBase /web # Dropped the / suffix otherwise the rewrites get //
## RewriteRule ^index\.php$ - [L] - # Removed because the Conditions below should be doing this?
RewriteRule ^$ /about-me [L] # Redirect homepage
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L] # dropped the /web prefix as that is managed by the RewriteBase
Results:
I'm looking for a way to have the URL
site.com/collection/name
serve the content that is actually located at...
site.com/collection/?collection_name=name
The website is running on WordPress, and is currently using the default .htaccess rules located in the root:
# 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
Because it's on WordPress, it's currently looking for a page /collection/name that doesn't exist, and produces a 404 error.
There should be an index file under the folder "name"
If so, you can try this:
RewriteEngine On
RewriteBase /
RewriteRule ^/$ /collection/name/index.php
RewriteRule ^([a-zA-Z0-9_-]+)/$ /collection/?collection_name=$1
This is a generic rule that works in many similar occasions. Modify it to suit your website...
I just migrated a site that was written quite a while ago to wordpress.
Doing this caused the url structure to be different now using mod-rewrite. I realized after I put the new site live that there are emails that have been sent out for customers to redeem their gift certificates from the site using the old URL.
My question is, with htaccess is there a url redirect that I can do and keep the get information with it. For example, I would need this url:
www.test.com/redeem.php?id=123
to redirect to:
www.test.com/redeem/now/?id=123
If there's no solution with .htaccess, does anyone have any solution for PHP?
Here's what my htaccess file looks like now:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Thanks for your help.
whether it will be like you want
http://test.com/redeem/now/read/2
the .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
using permalink wordpress
What I ended up doing was writing this code in the header file and it works.
<?php
if (array_shift(explode('?', $_SERVER['REQUEST_URI'])) == "/redeem.php") {
header ('Location: /gift-certificates/redeem/?id=' . $_GET["id"] );
}?>