I have a daunting problem with dynamic redirects that I have to do on WordPress website that was before an aspx website.
I am looking for advice for a week now and tried almost everything with different outcomes but none proved successful.
I need to redirect complex URLs such as:
/Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default.aspx?SortField=ProductName%2CProductName
to something simple like
http://domain.com/folder/
I've used number of ideas including loads from StackOverflow but none seem to tackle this specific example. Using standard Redirect 301 rule will work for as long as I don't have ? in the link. I understand this is beyond the scope of Redirect 301 and I need to use RewriteRule.
I tried this (got this from the excel spreadsheet for dynamic urls redirection):
RewriteCond %{QUERY_STRING} ^SortField=ProductName%2CProductName$
RewriteRule ^Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default\.aspx$ http://domain.com/folder/? [R=301,L]
But still on entering the url it yields 404 page.
Here's my .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]
## messing up
RewriteCond %{QUERY_STRING} ^SortField=ProductName%2CProductName$
RewriteRule ^Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default\.aspx$ http://domain.com/folder/? [R=301,L]
</IfModule>
Do I place it correctly? Is the code right? I would appreciate any ideas and clues.
Thanks a million
I have solve the mastery. The code was good just the placing was incorrect. After dozen tries and errors I found the correct formula. I had to amend placing of my redirect rule. Here is how it looks:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default\.aspx$ http://doamin.com/folder/? [R=301,L]
RewriteCond %{QUERY_STRING} ^SortField=ProductName%2CProductName$Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default.aspx?SortField=ProductName%2CProductName
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Related
So I need to do a .htaccess file that allow me to redirect the images link folder (wp-content/upload/) from a different site (http://widesigner.com.br/alessandra/) to be this one (http://www.alessandratonisi.com.br/site/)
Basically it's redirect some image links, example:
http://www.widesigner.com.br/alessandra/wp-content/uploads/2012/03/MG_6058-600x400.jpg
http://www.widesigner.com.br/alessandra/wp-content/uploads/2012/03/MG_9515.jpg
to
http://www.alessandratonisi.com.br/site/wp-content/uploads/2012/03/MG_6058-600x400.jpg
http://www.alessandratonisi.com.br/site/wp-content/uploads/2012/03/MG_9515.jpg
So what you need is redirect a website domain to another one for a specific folder. I don't know if the next line will help you to solve the problem, I don't think that will be the solution since I didn't test it.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/alessandra/(.*)$
RewriteRule ^(.*) https://www.alessandratonisi.com.br/site/%1 [R=302,NC]
Here are a lot of examples that could lead you to the correct answer: https://gist.github.com/ScottPhillips/1721489.
UPDATE:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/alessandra/(.*)$
RewriteRule ^(.*) https://www.alessandratonisi.com.br/site/%1 [R=302,NC]
RewriteBase /site/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
</IfModule>
# END WordPress
I want to redirect the page http://www.unived.in/ to http://www.unived.in/aboutus/.
I tried lots of plugins but the page still isn't redirected. In fact I have tried changing .htaccess but it still doesn't redirect properly. Sometimes it displays error 500.
Here is my .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond /home/unived/public_html/wp-content/sitemaps%{REQUEST_URI} -f
RewriteRule \.xml(\.gz)?$ /wp-content/sitemaps%{REQUEST_URI} [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
What do I need to do to make the redirection work?
Read this tutorial to learn more about mod_rewrite: http://www.webforgers.net/mod-rewrite/mod-rewrite-syntax.php
It's very detailed, and should help you accomplish your goal.
I have been using htaccess to remove rewrite certain URLs, however I am looking at something a little more complicated at the moment.
Our website blog (WordPress) used to have links like this:
/blog/postname/1387
However after redoing the website our links are now currently just
/postname
Would it be possible to redirect any uses from /blog/postname/1387 and get rid of the blog and number at the end via htaccess so it just contains the postname? At the moment I have:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^blog/(.*)/.*$ $1/
</IfModule>
Would love to hear any hints or tips, as this is not actually doing any redirecting, what am I doing wrong?
Let's just do a little cleanup:
<IfModule mod_rewrite.c>
#Turn on the RewriteEngine
RewriteEngine On
#Rewrites are all relative to /
RewriteBase /
#Explicit - If the request is for index.php, do nothing.
RewriteRule ^index\.php$ - [L]
#Conditional – Unless the file or directory specifically exists,
#If the request is for the old style blog URI, redirect to new style and stop.
#Otherwise, redirect to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)/.*$ $1/ [R=301,L,QSA]
RewriteRule . /index.php [L]
</IfModule>
I have a new website that is linked to from many places but the structure of the sitemap has changed. I need to redirect some old urls to the relevant new one.
The site also needs to keep its seo friendly url writing.
I have this in my .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteCond %{REQUEST_URI} !^/(csr|quality|schools|project_management|third_sector|nhs|about)$
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(csr|quality|schools|project_management|third_sector|nhs|about)$ /about-us [L,R=301]
</IfModule>
Going to /about redirects to /about-us (which is great), and going to /quality also redirects to /about-us (which is correct) too. However, going to /nhs or /schools (for instance) gives a 404. Why is this?
Any help will be appreciated.
[EDIT]
Removed [L] and it started working. Thanks
I think it's probably because your RewriteRule ^(.*)$ index.php/$1 [L] has an [L] flag (which means last.).
If the conditions are met for the first rule RewriteRule ^(.*)$ index.php/$1 [L] Apache will stop executing the other rules.
Try removing the [L]
I need a general rule that maps every URL in the /beta subdirectory to the corresponding URL in the root; essentially I need to remove /beta from all URLs.
In case it makes any difference, the URLs are dynamically generated by WordPress.
Currently my .htaccess file is:
# 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
Can you tell me where to put the new lines?
Thank you!
Could you try this?
RewriteEngine On
RewriteRule ^beta/(.*)$ http://example.com/$1 [R=301,L]
Your question is not entirely clear, but I would bet that what you want is having a Wordpress installed in somedir/beta appear in yoursite.com/ instead of yoursite.com/beta/. The rules you pasted are in somedir/beta/.htaccess, and are the default Wordpress rules. You must leave those alone.
What you need for that is to put the following rules in the root directory, as in, somedir/.htaccess, after changing example.com to your own domain. Your webserver first reads this root .htaccess, and when it does, it will know to rewrite requests to /beta.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/beta/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /beta/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ beta/index.php [L]
</IfModule>
More info in the Codex:
https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory