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"] );
}?>
Related
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'm struggling to get my .htaccess configured properly to setup a subdomain redirect for specific subdomains. I want to redirect (not mask) a subdomain to a specific page and repeat this configuration multiple times.
I'm hosted on a Google Compute Engine currently using Cloud DNS (used to host on Godaddy in which subdomain management was very simple)
before:
# 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>
after:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sat.theteachertutors.com$ [NC]
RewriteRule ^(.*)$ /private-sat-act-tutoring/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I tried the config above but the redirect does not work. The target url is: https://www.theteachertutors.com/private-sat-act-tutoring/
Any guidance/tips would be most appreciated. I've search for other examples but can't get this configuration to work at all, ie: http://sat.theteachertutors.com
Thanks
You were close to the solution, change the rewrite rule to this:
RewriteRule ^(.*)$ https://www.theteachertutors.com/private-sat-act-tutoring/$1 [R=301,L]
When you are redirecting to another domain/subdomain you have to use the full URL. Also I use R=301 to mark the redirect as a permanent redirect (by default rules that point to another domain use a 302 redirect).
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
I want to redirect some URL's using htaccess file.
My htaccess files is as under:
# 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>
Redirect /old-post-type/old-parent-post/old-post-slug/ /new-post-type/new-post-slug/
***** Some More URLs *****
# END WordPress
It should redirect to http://yourwebsitedomain.com/new-post-type/new-post-slug/ but, it is redirecting to http://yourwebsitedomain.com/new-post-type/new-post-slug/old-post-slug/
"old-post-slug/" automatically added to last I don't know why?
Any suggestions accepted.
I wouldn't recommend mixing mod_alias and mod_rewrite like that, the RewriteRule runs first, then runs again after Redirect, making strange things happen. Just use mod_rewrite all the way through, with the redirect before the other rules and with L flag, like so:
RewriteEngine On
RewriteBase /
#I put 302, use 301 if permanent redirect is what you are after.
RewriteRule ^old-post-type/old-parent-post/old-post-slug/$ /new-post-type/new-post-slug/ [L,R=302]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
And this only if you really must use htaccess for the redirects, like someone mentioned wordpress already has functionality for dealing with redirects.
Try this:
Redirect 301 /old-post-type/old-parent-post/old-post-slug/ http://your-domain.com/new-post-type/new-post-slug/
This should work. The 301 stands for "Moved Permanently".
I have an issue where I'm using Wordpress + W3 Total Cache + .htaccess + mod_rewrite.
Every querystring variable appended to a URL is causing Wordpress + Total Cache to re-cache a unique file for the request. I know of this Question that was asked but when using it, I feel like I'm not modifying my .htaccess file correctly - Redirection / htaccess rule to kill off query strings to use wordpress super cache
What is the correct way to modify the .htaccess file below to support ignoring all querystring variables but letting them be read by javascript on the page:
# 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>
Before all of your existing rules, but after any rules that you have redirecting (has an R flag), try this:
RewriteCond %{THE_REQUEST} \ /[^\ \?]*\?[^\ ]+
RewriteRule ^ %{REQUEST_URI}? [L]
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /teamin/index.php/$1 [QSA,PT,L]
</IfModule>
ErrorDocument 404 /404.html
This is i use in apache 2.4 ,you can try it !