htaccess redirect for a WordPress site

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!
SumukhaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kent DyerIT Security Analyst SeniorCommented:
"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
SumukhaAuthor Commented:
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
Jason C. LevineNo oneCommented:
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

SumukhaAuthor Commented:
Hi Jason,

had to Google "soup to nuts".

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

Thanks!
0
Jason C. LevineNo oneCommented:
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
SumukhaAuthor Commented:
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
Jason C. LevineNo oneCommented:
But is actual query string relevant to the redirection?
0
SumukhaAuthor Commented:
Don't understand the question
0
Jason C. LevineNo oneCommented:
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
SumukhaAuthor Commented:
Can there be something like

RewriteRule  ^(.*)blabla.aspx?QSubId=(*)   http://www.mysite.com/blabla/   [R=301]
0
SumukhaAuthor Commented:
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
Jason C. LevineNo oneCommented:
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
SumukhaAuthor Commented:
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
Jason C. LevineNo oneCommented:
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
SumukhaAuthor Commented:
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
Jason C. LevineNo oneCommented:
Sorry:

^blabla.aspx$

should be

^blabla\.aspx$
0
SumukhaAuthor Commented:
Nope. 404.
0
Jason C. LevineNo oneCommented:
The 404 means it's redirecting to a non-existent target.  Do you have the second half of the rule set up correctly?
0
SumukhaAuthor Commented:
Yes, the url works fine.
0
Jason C. LevineNo oneCommented:
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
SumukhaAuthor Commented:
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
Jason C. LevineNo oneCommented:
You may want to experiment with the Redirection plugin instead of what you have now.
0
SumukhaAuthor Commented:
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
SumukhaAuthor Commented:
Trying a different approach:
Adding to the robots.txt
Disallow: /?blabla.aspx=

Then have them remove from the index in webmaster tools.
0
Jason C. LevineNo oneCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SumukhaAuthor Commented:
In robots.txt or .htaccess?
0
Jason C. LevineNo oneCommented:
.htaccess.  I wouldn't do the robots.txt thing as that will hurt your SEO...
0
SumukhaAuthor Commented:
BINGO!
Redirect 301  /blabla.aspx   http://mysite.com/bloblo works!
0
SumukhaAuthor Commented:
AAA
Thanks, Jason!
0
Jason C. LevineNo oneCommented:
F**king finally.  Sheesh.

Sorry, Su.  I should have pivoted on you earlier.  Got stubborn with trying to use RewriteRule.
0
SumukhaAuthor Commented:
No problemo. Happy it works and learned something.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.