Solved

htaccess redirect for a WordPress site

Posted on 2013-02-03
31
587 Views
Last Modified: 2013-02-07
Hello,

I have moved a aspx site to the WordPress platform and need to redirect a whole bundle of pages that do not exist anymore to a new directory.

All urls
http://mysite.com/blabla.aspx?QSubId=(some-quey-string)
need to be redirected to
http://mysite.com/blabla/

My .htaccess file already reads

# 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

How do I implement this?

Thanks!
0
Comment
Question by:Sumukha
  • 17
  • 13
31 Comments
 
LVL 17

Expert Comment

by:Kent Dyer
ID: 38848806
"Stealing" the one that we are using from Concrete5 should do the trick..

# -- concrete5 urls start --
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Open in new window


HTH,

Kent
0
 

Author Comment

by:Sumukha
ID: 38849251
Hi Kent,

thanks for posting.

I wouldn't know how to use that for my example.

How would that look for

http://mysite.com/blabla.aspx?QSubId=(some-quey-string)
redirected to
http://mysite.com/blabla/

?

Thanks!
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38852066
Su,

Do you know how to write RewriteRules for Apache and are just asking where to place it vis-a-vis WordPress or this a soup-to-nuts request?
0
 

Author Comment

by:Sumukha
ID: 38852120
Hi Jason,

had to Google "soup to nuts".

Yes, it is that: what to place where in my .htaccess file.

Thanks!
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38852190
Okay, so from your sample above, you don't care about the query string.  The rewrite rule would then be:

RewriteRule  ^(.*)\.aspx   http://www.mysite.com/$1   [R=301]

Place this right after RewriteBase / so it becomes the first RewriteRule in the system.
0
 

Author Comment

by:Sumukha
ID: 38852461
It is actually targeting a particular query string starting with
blabla.aspxQSubId=(some-quey-string)

All those queries should be redirected to a folder .com/blabla/
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38852500
But is actual query string relevant to the redirection?
0
 

Author Comment

by:Sumukha
ID: 38852635
Don't understand the question
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38852659
You said:
"It is actually targeting a particular query string starting with
blabla.aspxQSubId=(some-quey-string)"

My response:

Are we matching one particular query string to force the redirect or just redirecting all accesses blabla.aspx to the matching WordPress URL?
0
 

Author Comment

by:Sumukha
ID: 38852666
Can there be something like

RewriteRule  ^(.*)blabla.aspx?QSubId=(*)   http://www.mysite.com/blabla/   [R=301]
0
 

Author Comment

by:Sumukha
ID: 38852690
We overlapped.
We are redirecting all accesses blabla.aspx to a specific WordPress directory.
The actual directory has a different blabla name than the queries, let's call the directory bloblo.

So any mysite.com/blabla.aspx(...) goes to mysite.com/bloblo/.

Sorry for being not specific before.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38852927
Okay, my original RewriteRule should work then.  The query string doesn't need a match since you don't plan to do anything with it.
0
 

Author Comment

by:Sumukha
ID: 38853086
Lost you again.
There is no blabla and no bloblo in your rule - how will the specific redirect happen then?

Urls with dudidu.aspx will be managed differently...
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38853376
Okay.  My rule is a generic redirector and assume page1.aspx will be redirected using the same pattern as page2.aspx and so on:

RewriteRule  ^(.*)\.aspx$   http://www.mysite.com/$1   [R=301]

Open in new window


The ^(.*)\.aspx$ is a regular expression.  It will match page1 or page2 or whatever appears before the .aspx.

The $1 is a backreference that takes the (.*) part and makes it the URL.  So /page1.aspx becomes mysite.com/page1

If you prefer to not have one rule to rule them all, then simply remove the regular expression wildcard match and go with something like this:

RewriteRule  ^blabla.aspx$   http://www.mysite.com/blabla   [R=301]

Open in new window

0
 

Author Comment

by:Sumukha
ID: 38853417
The code makes sense, but does not work on my site.
Here is what my htaccess looks like now:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^blabla.aspx$   http://mysite.com/bloblo  [R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38853436
Sorry:

^blabla.aspx$

should be

^blabla\.aspx$
0
 

Author Comment

by:Sumukha
ID: 38853464
Nope. 404.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38853477
The 404 means it's redirecting to a non-existent target.  Do you have the second half of the rule set up correctly?
0
 

Author Comment

by:Sumukha
ID: 38853512
Yes, the url works fine.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38853733
Okay, there's an alternate format to add the rules.  Try this instead:

Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^blabla\.aspx$   http://mysite.com/bloblo  [R=301]

# 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>

Open in new window


This is the longer form and a little redundant.  If it still doesn't work, we can either switch to the Apache redirect directive or try a plugin.  I hate using plugins for redirection but depending on how the minutiae of the Apache configuration files are set, sometimes that works best with WordPress.
0
 

Author Comment

by:Sumukha
ID: 38855157
Also not working.
By the way I do have the 404 redirected plugin in WordPress which works perfectly for single urls - capture them and create a redirect.
I am asking this question here, because I could not figure out a way to do this type of bulk redirect in that plugin (no support there).
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38860564
You may want to experiment with the Redirection plugin instead of what you have now.
0
 

Author Comment

by:Sumukha
ID: 38864637
That is not compatible with my version. I also cannot disable the one I am using since it is already managing many other redirects.
0
 

Author Comment

by:Sumukha
ID: 38865354
Trying a different approach:
Adding to the robots.txt
Disallow: /?blabla.aspx=

Then have them remove from the index in webmaster tools.
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 200 total points
ID: 38865395
Well that will drop your page ranks considerably. Let's try redirection via Redirect instead of RewriteRule.  Try

Redirect 301  /blabla.aspx   http://mysite.com/bloblo

or

RedirectMatch 301  ^/blabla\.asp$   http://mysite.com/bloblo

Above the WordPress block.  I am assuming that /blabla.aspx is off the site root.
0
 

Author Comment

by:Sumukha
ID: 38865452
In robots.txt or .htaccess?
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38865459
.htaccess.  I wouldn't do the robots.txt thing as that will hurt your SEO...
0
 

Author Comment

by:Sumukha
ID: 38866124
BINGO!
Redirect 301  /blabla.aspx   http://mysite.com/bloblo works!
0
 

Author Closing Comment

by:Sumukha
ID: 38866127
AAA
Thanks, Jason!
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 38866147
F**king finally.  Sheesh.

Sorry, Su.  I should have pivoted on you earlier.  Got stubborn with trying to use RewriteRule.
0
 

Author Comment

by:Sumukha
ID: 38866188
No problemo. Happy it works and learned something.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Read about why website design really matters in today's demanding market.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now