.htaccess - 301 redirect with variables

Hello, How can I do a mod rewrite so I can redirect old urls with variables to new pages. For example here is the code that is not working with variables in them. Here you can see the variable “id” in the url and trying to redirect to new pages. Any ideas?

RewriteRule ^gallery/full-face-photos.asp?id=AJ$ new-page1.html [R=301,L]
RewriteRule ^hairline/hairline-photos.asp?id=GG$ other-hairline2.html [R=301,L]

The ?id=AJ part is known as the query string and you can’t match for that in a RewriteRule. However, you can match it in a RewriteCond – which is basically an extra condition for the RewriteRule to fire.
Also, you need to escape the dot in .asp, otherwise it reads “any character, followed by ‘asp’”, so it would also match URLs like hairline-photoszasp

Try this:


RewriteCond %{QUERY_STRING} ^id=AJ$ [NC]
RewriteRule ^gallery/full-face-photos\\.asp$ new-page1.html [R=301,L]

I’ll let you figure the second one out for yourself, shouldn’t be too hard :slight_smile:

nailed it, thank you!

Hmm, The first redirect in the file works, however the other variables are not… did I miss something?

RewriteCond %{QUERY_STRING} ^id=aa$ [NC]
RewriteRule ^next/full-face-photos\\.asp$ patient-aa.html [R=301,L]

RewriteCond %{QUERY_STRING} ^id=ao$ [NC]
RewriteRule ^next/full-face-photos\\.asp?id=ao$ patient-ao.html [R=301,L]

RewriteCond %{QUERY_STRING} ^id=az$ [NC]
RewriteRule ^next/full-face-photos\\.asp?id=az$ patient-az.html [R=301,L]

RewriteCond %{QUERY_STRING} ^id=bf$ [NC]
RewriteRule ^next/full-face-photos\\.asp?id=bf$ patient-bf.html [R=301,L]

RewriteCond %{QUERY_STRING} ^id=bi$ [NC]
RewriteRule ^next/full-face-photos\\.asp?id=bi$ patient-bi.html [R=301,L]

RC,

If the ?id=yadda-yadda is a query string and can never be matched in a RewriteRule, why would you remove it from the first one and leave it in the rest?

Then, too, specificity is important (and you did not properly define your requirements for your redirection) as you have a pattern you can take advantage of.

If you can handle ANY two letter pair as the value for your id key, you can use:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=([a-z]{2})$
RewriteRule ^next/full-face-photos\\.asp$ patient-%1.html [R=301,L]

If not, create a list in the atom thusly:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=(aa|ao|az|bf|bi)$
RewriteRule ^next/full-face-photos\\.asp$ patient-%1.html [R=301,L]

IMHO, always look for patterns that you can use the power of regex to simplify your code.

Regards,

DK

thanks dk, i withheld some of those details to keep the post concise and figured I would be able to muscle through my list once i was able to redirect them one-by-one.

RC,

No Worries. If I had looked closely, I would have seen via your example code the first time and commented on the pattern but you’ve been around enough to be able to put it together now.

Regards,

DK

I have one more question.

I need to redirect the old search page URL to the new one and carry the variable over to the actual redirect page.

How can I redirect this page with query string
search/search.asp?zoom_query=search+word

To this page with query string
search.html?Q=search+word

So is this correct to add a new rewrite query string to my .htaccess file to setup a new redirect for the search and search variable:

RewriteCond %{QUERY_STRING} ^zoom_query=(%1})$
RewriteRule ^search/search.\\.asp$ search.html?Q=%1 [R=301,L]

RC,

It would have been easier if your key didn’t change because the query string would carry over unaffected. Oh, well.

Your first %1} is inappropriate. You could specify the expected character set or use (.*) to capture (and create %1) and then it would work:

RewriteCond %{QUERY_STRING} ^zoom_query=([-a-zA-Z\\+\\ ]+)$
RewriteRule ^search/search.\\.asp$ search.html?Q=%1 [R=301,L]

Regards,

DK

Thats not working… I’m sure Im not being concise enough again. Here is the actual page. The first link is fine in the search results. The following links with search.asp are the ones Im trying to redirect. Click the second search result on this page and you will see its not redirecting

http://www.newhair.com/search.html?Q=steve+hartman

RC,

Aw, the second link is to http://www.newhair.com/search/search.asp%3Fzoom_query%3Dsteve%26zoom_page%3D1%26zoom_per_page%3D10%26zoom_cat%3D-1%26zoom_and%3D0 with the query string %3Fzoom_query%3Dsteve%26zoom_page%3D1%26zoom_per_page%3D10%26zoom_cat%3D-1%26zoom_and%3D0. Why in the world would you escape the query string’s marker (?), the ='s and the &'s? That’s just plain crazy (and defeats the purpose of the ? to denote the separation of the URI from the query string).

Regards,

DK

I did not intend to escape any of those characters, I guess that is what google has cached for the older site from the last developer?

What is my next step to get this to work? I either need to redirect to the new page or tell google search.asp is a dead link so it is no longer indexed.

Please advise! And I am more of a PHP guy than regex/C+ or w/e is used to make this happen :confused:

RC,

I just ran a test on a website of a client’s to test the effect of the encoded ?, = and &. They work as the unencoded query string would work.

Therefore, the problem with the second (and, presumably, all the following) URI?query_string links is that they contain more than just the zoom_query key that you mentioned above, i.e., zoom_page, zoom_per_page, zoom_cat and zoom_and. What about those keys? Specificity IS important, as you’ve just discovered!

If you don’t care about the other query string keys, merely remove the $ from the code above. If you do, LEAVE THE QUERY STRING ALONE and change the Q in your new $_GET array to zoom_page and deal with it (and the others) any way you wish. The problem you’re having is in requiring a change in the key (and number of key/value pairs to handle), not in the mod_rewrite code.

If it were me, I would have planned the change from ASP to PHP and left the key/value pairs alone so that the PHP versions would handle any change in the database field names in the query statement.

Regards,

DK

Those other keys are not important and I would like to ignore them.

Ive updated my code and removed the $ and also am now using “zoom_query” on my new page (even though it shouldn’t matter), however its still not redirecting:

RewriteCond %{QUERY_STRING} ^zoom_query=([-a-zA-Z\\+\\ ]+)
RewriteRule ^search/search.\\.asp$ search.html?zoom_query=%1 [R=301,L]

And here is the new search page with updated $_GET variable:
http://www.newhair.com/search.html?zoom_query=steve+hartman

Did i remove the correct “$”? I’ve tried it several ways and the redirect is still not working. thanks again for helping me figure this out

RC,

The point of using the same key/value pairs is that a redirection leaves the query string unaffected (unless you create a new query string or kill the old one with a ? and nothing following in the redirection). Therefore, delete the RewriteCond statement and remove the ?zoom_query=%1 from the redirection:

RewriteEngine on
RewriteRule ^search/search.\\.asp$ search.html [R=301,L]

If you’re paranoid, add the QSA flag ( [R=301,L] becomes [R=301,L,QSA] ) to ensure that the pre-existing query string is appended. This is NOT necessary in the code immediately above as I’ve removed the query string you created in the redirection (so the query string is unaffected, i.e., delivered as it existed - you can ignore the superfluous key/value pairs in the search.html and they’ll not have any affect).

Regards,

DK

Ok, I’ve updated my code and no luck. Here is my full .htaccess file with your last tag in red and towards the bottom



# MODX supports Friendly URLs via this .htaccess file. You must serve web
# pages via Apache with mod_rewrite to use this functionality, and you must
# change the file name from ht.access to .htaccess.
#
# Make sure RewriteBase points to the directory where you installed MODX.
# E.g., "/modx" if your installation is in a "modx" subdirectory.
#
# You may choose to make your URLs non-case-sensitive by adding a NC directive
# to your rule: RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]

RewriteEngine On
RewriteBase /



# Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^example-domain-please-change\\.com [NC]
#RewriteRule (.*) http://example-domain-please-change.com/$1 [R=301,L]
#
# or for the opposite domain.com -> www.domain.com use the following
# DO NOT USE BOTH
#
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\\.newhair\\.com [NC]
RewriteRule (.*) http://www.newhair.com/$1 [R=301,L]



# Rewrite secure requests properly to prevent SSL cert warnings, e.g. prevent
# https://www.domain.com when your cert only allows https://secure.domain.com
#RewriteCond %{SERVER_PORT} !^443
#RewriteRule (.*) https://example-domain-please-change.com.com/$1 [R=301,L]

RewriteRule ^treatment/fue-fox-megasession.asp$ fue-megasession.html [R=301,L]
RewriteRule ^fue2/$ fue2.html [R=301,L]
RewriteRule ^fue/$ fue-introduction-to-follicular-unit-extraction-techniques.html [R=301,L]
RewriteRule ^treatment/fut-automated-devices.asp$ automated-devices.html [R=301,L]
RewriteRule ^treatment/fut-treating-women.asp$ treating-women.html [R=301,L]
RewriteRule ^treatment/fut-racial-variations.asp$ racial-variations.html [R=301,L]
RewriteRule ^treatment/fut-megasessions.asp$ megasessions.html [R=301,L]
RewriteRule ^treatment/fut-fast-track-method.asp$ nhi-fast-track%C2%AE-method.html [R=301,L]
RewriteRule ^treatment/fut-suturing-techniques.asp$ suturing-techniques.html [R=301,L]
RewriteRule ^treatment/fut-follicular-units.asp$ follicular-units.html [R=301,L]
RewriteRule ^treatment/fut-microscopic-dissection.asp$ stereo-microscopic-dissection.html [R=301,L]
RewriteRule ^treatment/fut-single-strip-harvesting.asp$ single-strip-harvesting.html [R=301,L]
RewriteRule ^treatment/fut-nhi-master-plan.asp$ nhi-master-plan.html [R=301,L]
RewriteRule ^treatment/follicular-unit-transplants.asp$ follicular-unit-transplants.html [R=301,L]
RewriteRule ^treatment/basics-post-op.asp$ post-op-course-in-follicular-unit-transplantation.html [R=301,L]
RewriteRule ^treatment/basics-procedure.asp$ understanding-the-procedure.html [R=301,L]
RewriteRule ^treatment/basics-overview.asp$ an-overview-of-hair-transplantation.html [R=301,L]
RewriteRule ^treatment/hair-transplant-basics.asp$ hair-transplant-basics.html [R=301,L]
RewriteRule ^treatment/index.asp$ getting-started/ [R=301,L]
RewriteRule ^info/contact.asp$ contact-information.html [R=301,L]
RewriteRule ^info/news-views.asp$ 2004-golden-follicle-award.html [R=301,L]
RewriteRule ^info/doctor-pak.asp$ jae-pak-m.d.html [R=301,L]
RewriteRule ^info/doctor-rassman.asp$ william-r.-rassman-m.d.html [R=301,L]
RewriteRule ^info/hair-doctors.asp$ about-us/ [R=301,L]
RewriteRule ^info/history-timeline.asp$ nhi-timeline.html [R=301,L]
RewriteRule ^info/history.asp$ history-of-nhi.html [R=301,L]
RewriteRule ^info/nhi-way.asp$ the-nhi-way.html [R=301,L]
RewriteRule ^info/events.asp$ upcoming-events.html [R=301,L]
RewriteRule ^info/index.asp$ about-us/ [R=301,L]
RewriteRule ^next/hair-loss-questions-faq.asp$ faq.html [R=301,L]
RewriteRule ^fees/$ fees-and-financing.html [R=301,L]
RewriteRule ^next/request-info.asp$ contact-information.html [R=301,L]
RewriteRule ^next/consultation.asp$ schedule-a-consultation.html [R=301,L]
RewriteRule ^next/hair-transplant-videos.asp?fl=no$ videos/ [R=301,L]
RewriteRule ^next/repair-story-dean.asp$ procedure-1-the-surgery-page-1.html [R=301,L]
RewriteRule ^next/other-photo-gallery.asp$ other-hair-restoration-photos/
RewriteRule ^next/repair-photo-gallery.asp$ repair-work-photos/
RewriteRule ^next/hairline-photo-gallery.asp$ hairline-photos/
RewriteRule ^next/full-face-photo-gallery.asp$ full-face-photos/
RewriteRule ^next/hair-restoration-photos.asp$ gallery/ [R=301,L]
RewriteRule ^resources/links.asp$ expert-links.html [R=301,L]
RewriteRule ^resources/nhi-newsletters.asp$ nhi-newsletters.html [R=301,L]
RewriteRule ^resources/medical-publications.asp$ follicular-transplantation-patient-evaluation-and-surgical-planning.html [R=301,L]
RewriteRule ^resources/hair-loss-in-women.asp$ hair-loss-in-women.html [R=301,L]
RewriteRule ^resources/assessing-hair-loss.asp$ assessing-hair-loss.html [R=301,L]
RewriteRule ^resources/hair-loss-causes.asp$ causes-of-hair-loss.html [R=301,L]
RewriteRule ^resources/index.asp$ expert-resources/ [R=301,L]
RewriteRule ^treatment/other-laser-therapy.asp$ laser-hair-transplants.html [R=301,L]
RewriteRule ^treatment/other-cosmetic-camouflage.asp$ cosmetic-camouflage.html [R=301,L]
RewriteRule ^treatment/other-hair-systems.asp$ hair-systems.html [R=301,L]
RewriteRule ^treatment/other-tissue-expansion.asp$ tissue-expansion.html [R=301,L]
RewriteRule ^treatment/other-flaps.asp$ flaps.html [R=301,L]
RewriteRule ^treatment/other-scalp-reductions.asp$ scalp-reductions.html [R=301,L]
RewriteRule ^treatment/other-laser-hair-transplants.asp$ low-laser-light-therapy-for-hair-loss.html [R=301,L]
RewriteRule ^treatment/other-plug-grafts.asp$ plug-type-grafts.html [R=301,L]
RewriteRule ^treatment/other-dilators.asp$ dilators.html [R=301,L]
RewriteRule ^treatment/other-mini-micrografting.asp$ mini-micrografting.html [R=301,L]
RewriteRule ^treatment/other-cloning-hair.asp$ cloning-hair.html [R=301,L]
RewriteRule ^treatment/other-medications.asp$ medications.html [R=301,L]
RewriteRule ^treatment/other-hair-loss-treatments.asp$ low-laser-light-therapy-for-hair-loss.html [R=301,L]
RewriteRule ^treatment/corrective-fix-scarred-area.asp$ scarred-areas.html [R=301,L]
RewriteRule ^treatment/corrective-repair-scalp-reduction.asp$ scalp-reductions.html [R=301,L]
RewriteRule ^treatment/corrective-hide-large-grafts.asp$ camouflaging-large-grafts.html [R=301,L]
RewriteRule ^treatment/corrective-repair-strategies.asp$ repair-strategies.html [R=301,L]
RewriteRule ^treatment/corrective-wasted-donor-hair.asp$ wasted-donor-hair.html [R=301,L]
RewriteRule ^treatment/corrective-fix-old-plugs.asp$ fixing-old-plugs.html [R=301,L]
RewriteRule ^treatment/corrective-procedures.asp$ fixing-old-plugs.html [R=301,L]
RewriteRule ^next/repair-story-dean-101.asp$ procedure-1-the-surgery-page-1.html [R=301,L]
RewriteRule ^next/repair-story-dean-101a.asp$ procedure-1-the-surgery-page-2.html [R=301,L]
RewriteRule ^next/repair-story-dean-101b.asp$ procedure-1-the-surgery-page-3.html [R=301,L]
RewriteRule ^next/repair-story-dean-101c.asp$ procedure-1-the-surgery-page-4.html [R=301,L]
RewriteRule ^next/repair-story-dean-101d.asp$ procedure-1-the-surgery-page-5.html [R=301,L]
RewriteRule ^next/repair-story-dean-102.asp$ procedure-1-9-days-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-103.asp$ procedure-1-16-days-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-104.asp$ procedure-1-23-days-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-105.asp$ procedure-1-60-days-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-201.asp$ procedure-2-the-surgery-page-1.html [R=301,L]
RewriteRule ^next/repair-story-dean-201a.asp$ procedure-2-the-surgery-page-2.html [R=301,L]
RewriteRule ^next/repair-story-dean-201b.asp$ procedure-2-the-surgery-page-3.html [R=301,L]
RewriteRule ^next/repair-story-dean-201c.asp$ procedure-2-the-surgery-page-4.html [R=301,L]
RewriteRule ^next/repair-story-dean-201d.asp$ procedure-2-the-surgery-page-5.html [R=301,L]
RewriteRule ^next/repair-story-dean-201e.asp$ procedure-2-the-surgery-page-6.html [R=301,L]
RewriteRule ^next/repair-story-dean-202.asp$ procedure-2-21-days-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-203.asp$ procedure-2-35-days-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-204.asp$ procedure-2-6-weeks-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-205.asp$ procedure-2-2-months-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-301.asp$ procedure-3-the-surgery-page-1.html [R=301,L]
RewriteRule ^next/repair-story-dean-301a.asp$ procedure-3-the-surgery-page-2.html [R=301,L]
RewriteRule ^next/repair-story-dean-301b.asp$ procedure-3-the-surgery-page-3.html [R=301,L]
RewriteRule ^next/repair-story-dean-301c.asp$ procedure-3-the-surgery-page-4.html [R=301,L]
RewriteRule ^next/repair-story-dean-301d.asp$ procedure-3-the-surgery-page-5.html [R=301,L]
RewriteRule ^next/repair-story-dean-301e.asp$ procedure-3-the-surgery-page-6.html [R=301,L]
RewriteRule ^next/repair-story-dean-301f.asp$ procedure-3-the-surgery-page-7.html [R=301,L]
RewriteRule ^next/repair-story-dean-301g.asp$ procedure-3-the-surgery-page-8.html [R=301,L]
RewriteRule ^next/repair-story-dean-301h.asp$ procedure-3-the-surgery-page-9.html [R=301,L]
RewriteRule ^next/repair-story-dean-301i.asp$ procedure-3-the-surgery-page-10.html [R=301,L]
RewriteRule ^next/repair-story-dean-302.asp$ procedure-3-6-months-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-303.asp$ procedure-3-summary.html [R=301,L]

[B][COLOR="#FF0000"]RewriteRule ^search/search.\\.asp$ search.html [R=301,L][/COLOR][/B]

RewriteCond %{QUERY_STRING} ^pt=(ao|az|bf|bi|cc|cf|ck|ec|ec2|ej|es|fc|fc2|gc|gi|go|gq|iz|jq|ki|lf|lk|ll|ml|oi|ql|qq|rd|rf|si|uq|zu|aq|as|bi|cz|is|jg|jh|ji|kl|kq|le|lz|oi|qb|qi|ri|sz|ul|vi|vq|zo|bf|jq|li|or|wr|bg|rq|uk|ll|ru|mja|mjb|ai|aq|av|ba|bl|cq|cq2|ei|ek|eq|fi|fr|gf|gi|gr|hl|if|iq|is|jd|jq|jq2|ki|ko|lb|lc|lc2|lj|lr|lu|ma|ni|od|oj|qa|qi|qk|qo|qs|ri|ri2|rm|rq|su|vg|vs|vv|xg|xw|zf|ng|ds|bb|nh|vt|nk|gg|sk|et|cl|at|dk|us|cs|dd|hq|kg|ok|gk|mu|lx|dl|sq|dm|qt|cm|bn|bt|df|mt|xl|xk|tm|vl|cb|gn|dn|gb|qe|sv|nq|cd|xj|td|ik|be|kb|kk|lt|lv|mn|no|ts|cg|db|dt|ee|ef|eu|ft|ic|iu|mj|de|en|nn|ws|mk|xma|th|mc|do|tv|it|dp|ct|tt|ks|ns|tw|tu|dq|nf|ce|aj|uo|eo|el|nt|xs|gp|iv|ktb|eb|nu|tx|ir|te|tl|ch|qf|lg|kp|nj|nl|ci|ld|np|tg|ou|gs|tda|ttc|tn|tc|tuh|sc|oh|os|on|nqb|nkb|nx|ms|me|lbb|lxb|ikc|eja|ekc|efw|dla|du|ctb|cx|xea|cca|cna|cea|ceb|bfa|tta|uh|zl|ze|tlb|hka|bba|kda|dia|kga|sfa|fla|tla|hna|ita|kla|klb|nua|qsa|hta|qla|cqa|itb|kqa|tba|gla|ola|joe|nna|kta|nxa|nsa|hwa|ssa|nxb|bbb|tlc|ena|sda|msa|ktc|kdb|tca|cka|kca|mst|olb|bta|eka|bpa|dta|tma|nta|ebb|esa|tcb|eca|enb|nea|ima|nia|mua|kma|kib|kfa)$
RewriteRule ^next/full-face-photos\\.asp$ patient-%1.html [R=301,L]







# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]



# Make sure .htc files are served with the proper MIME type, which is critical
# for XP SP2. Un-comment if your host allows htaccess MIME type overrides.

#AddType text/x-component .htc



# If your server is not already configured as such, the following directive
# should be uncommented in order to set PHP's register_globals option to OFF.
# This closes a major security hole that is abused by most XSS (cross-site
# scripting) attacks. For more information: http://php.net/register_globals
#
# To verify that this option has been set to OFF, open the Manager and choose
# Reports -> System Info and then click the phpinfo() link. Do a Find on Page
# for "register_globals". The Local Value should be OFF. If the Master Value
# is OFF then you do not need this directive here.
#
# IF REGISTER_GLOBALS DIRECTIVE CAUSES 500 INTERNAL SERVER ERRORS :
#
# Your server does not allow PHP directives to be set via .htaccess. In that
# case you must make this change in your php.ini file instead. If you are
# using a commercial web host, contact the administrators for assistance in
# doing this. Not all servers allow local php.ini files, and they should
# include all PHP configurations (not just this one), or you will effectively
# reset everything to PHP defaults. Consult www.php.net for more detailed
# information about setting PHP directives.

#php_flag register_globals Off



# For servers that support output compression, you should pick up a bit of
# speed by un-commenting the following lines.

#php_flag zlib.output_compression On
#php_value zlib.output_compression_level 5



# The following directives stop screen flicker in IE on CSS rollovers. If
# needed, un-comment the following rules. When they're in place, you may have
# to do a force-refresh in order to see changes in your designs.

#ExpiresActive On
#ExpiresByType image/gif A2592000
#ExpiresByType image/jpeg A2592000
#ExpiresByType image/png A2592000
#BrowserMatch "MSIE" brokenvary=1
#BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
#BrowserMatch "Opera" !brokenvary
#SetEnvIf brokenvary 1 force-no-vary


I suppose the old search file was search.asp, in which case the dot in red


RewriteRule ^search/search[COLOR="#FF0000"][B].[/B][/COLOR]\\.asp$ search.html [R=301,L]

is superfluous and breaks the rule (no pun intended lol)

RC,

I keep posting that RewriteBase was created to UNDO a mod_alias redirection (e.g., Redirect) before allowing mod_rewrite to perform its magic. You don’t have a Redirect in your .htaccess so your RewriteBase can only muddle your mod_rewrite redirections.

Second, you have an additional dot character in your search RewriteRule. Remove the first one.

Of major importance is that your .htaccess is ridiculously long. Be aware that each and every request made to your server requires that the .htaccess be loaded, parsed and each redirection will require at least a second pass through the code. This is tremendously time consuming and is an abuse of the server. If it’s your server, that’s your choice but I would move all code (which you’ve tested thoroughly) to your Apache2.conf (httpd.conf) file so it’s only read once (when the server starts).

Regards,

DK

Thank you, once I get everything redirecting properly I will append my http.conf file.

Ok so I’ll have to remove RewriteBase for this search.asp to work? This .htaccess file is the default that comes with installing the MODX CMS, so I’m a little wary of tweaking anything unless you literally spell it out for me where I can copy/paste the code to test (and have a backup of course :slight_smile: )

I’ve updated that section of code to remove the extra period, and as you said from the above point its not working because of Rewrite Base. What exact changes do you suggest I do to the below code, while being careful to allow the MODX CMS to still have the rewrite code it needs to work. If you have a paypal account I’d love to buy you a case of beer or a puppy.

# MODX supports Friendly URLs via this .htaccess file. You must serve web
# pages via Apache with mod_rewrite to use this functionality, and you must
# change the file name from ht.access to .htaccess.
#
# Make sure RewriteBase points to the directory where you installed MODX.
# E.g., "/modx" if your installation is in a "modx" subdirectory.
#
# You may choose to make your URLs non-case-sensitive by adding a NC directive
# to your rule: RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]

RewriteEngine On
RewriteBase /



# Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
#RewriteCond %{HTTP_HOST} .
#RewriteCond %{HTTP_HOST} !^example-domain-please-change\\.com [NC]
#RewriteRule (.*) http://example-domain-please-change.com/$1 [R=301,L]
#
# or for the opposite domain.com -> www.domain.com use the following
# DO NOT USE BOTH
#
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\\.newhair\\.com [NC]
RewriteRule (.*) http://www.newhair.com/$1 [R=301,L]



# Rewrite secure requests properly to prevent SSL cert warnings, e.g. prevent 
# https://www.domain.com when your cert only allows https://secure.domain.com
#RewriteCond %{SERVER_PORT} !^443
#RewriteRule (.*) https://example-domain-please-change.com.com/$1 [R=301,L]

RewriteRule ^treatment/fue-fox-megasession.asp$ fue-megasession.html [R=301,L]
RewriteRule ^fue2/$ fue2.html [R=301,L]
RewriteRule ^fue/$ fue-introduction-to-follicular-unit-extraction-techniques.html [R=301,L]
RewriteRule ^treatment/fut-automated-devices.asp$ automated-devices.html [R=301,L]
RewriteRule ^treatment/fut-treating-women.asp$ treating-women.html [R=301,L]
RewriteRule ^treatment/fut-racial-variations.asp$ racial-variations.html [R=301,L]
RewriteRule ^treatment/fut-megasessions.asp$ megasessions.html [R=301,L]
RewriteRule ^treatment/fut-fast-track-method.asp$ nhi-fast-track%C2%AE-method.html [R=301,L]
RewriteRule ^treatment/fut-suturing-techniques.asp$ suturing-techniques.html [R=301,L]
RewriteRule ^treatment/fut-follicular-units.asp$ follicular-units.html [R=301,L]
RewriteRule ^treatment/fut-microscopic-dissection.asp$ stereo-microscopic-dissection.html [R=301,L]
RewriteRule ^treatment/fut-single-strip-harvesting.asp$ single-strip-harvesting.html [R=301,L]
RewriteRule ^treatment/fut-nhi-master-plan.asp$ nhi-master-plan.html [R=301,L]
RewriteRule ^treatment/follicular-unit-transplants.asp$ follicular-unit-transplants.html [R=301,L]
RewriteRule ^treatment/basics-post-op.asp$ post-op-course-in-follicular-unit-transplantation.html [R=301,L]
RewriteRule ^treatment/basics-procedure.asp$ understanding-the-procedure.html [R=301,L]
RewriteRule ^treatment/basics-overview.asp$ an-overview-of-hair-transplantation.html [R=301,L]
RewriteRule ^treatment/hair-transplant-basics.asp$ hair-transplant-basics.html [R=301,L]
RewriteRule ^treatment/index.asp$ getting-started/ [R=301,L]
RewriteRule ^info/contact.asp$ contact-information.html [R=301,L]
RewriteRule ^info/news-views.asp$ 2004-golden-follicle-award.html [R=301,L]
RewriteRule ^info/doctor-pak.asp$ jae-pak-m.d.html [R=301,L]
RewriteRule ^info/doctor-rassman.asp$ william-r.-rassman-m.d.html [R=301,L]
RewriteRule ^info/hair-doctors.asp$ about-us/ [R=301,L]
RewriteRule ^info/history-timeline.asp$ nhi-timeline.html [R=301,L]
RewriteRule ^info/history.asp$ history-of-nhi.html [R=301,L]
RewriteRule ^info/nhi-way.asp$ the-nhi-way.html [R=301,L]
RewriteRule ^info/events.asp$ upcoming-events.html [R=301,L]
RewriteRule ^info/index.asp$ about-us/ [R=301,L]
RewriteRule ^next/hair-loss-questions-faq.asp$ faq.html [R=301,L]
RewriteRule ^fees/$ fees-and-financing.html [R=301,L]
RewriteRule ^next/request-info.asp$ contact-information.html [R=301,L]
RewriteRule ^next/consultation.asp$ schedule-a-consultation.html [R=301,L]
RewriteRule ^next/hair-transplant-videos.asp?fl=no$ videos/ [R=301,L]
RewriteRule ^next/repair-story-dean.asp$ procedure-1-the-surgery-page-1.html [R=301,L]
RewriteRule ^next/other-photo-gallery.asp$ other-hair-restoration-photos/
RewriteRule ^next/repair-photo-gallery.asp$ repair-work-photos/
RewriteRule ^next/hairline-photo-gallery.asp$ hairline-photos/
RewriteRule ^next/full-face-photo-gallery.asp$ full-face-photos/
RewriteRule ^next/hair-restoration-photos.asp$ gallery/ [R=301,L]
RewriteRule ^resources/links.asp$ expert-links.html [R=301,L]
RewriteRule ^resources/nhi-newsletters.asp$ nhi-newsletters.html [R=301,L]
RewriteRule ^resources/medical-publications.asp$ follicular-transplantation-patient-evaluation-and-surgical-planning.html [R=301,L]
RewriteRule ^resources/hair-loss-in-women.asp$ hair-loss-in-women.html [R=301,L]
RewriteRule ^resources/assessing-hair-loss.asp$ assessing-hair-loss.html [R=301,L]
RewriteRule ^resources/hair-loss-causes.asp$ causes-of-hair-loss.html [R=301,L]
RewriteRule ^resources/index.asp$ expert-resources/ [R=301,L]
RewriteRule ^treatment/other-laser-therapy.asp$ laser-hair-transplants.html [R=301,L]
RewriteRule ^treatment/other-cosmetic-camouflage.asp$ cosmetic-camouflage.html [R=301,L]
RewriteRule ^treatment/other-hair-systems.asp$ hair-systems.html [R=301,L]
RewriteRule ^treatment/other-tissue-expansion.asp$ tissue-expansion.html [R=301,L]
RewriteRule ^treatment/other-flaps.asp$ flaps.html [R=301,L]
RewriteRule ^treatment/other-scalp-reductions.asp$ scalp-reductions.html [R=301,L]
RewriteRule ^treatment/other-laser-hair-transplants.asp$ low-laser-light-therapy-for-hair-loss.html [R=301,L]
RewriteRule ^treatment/other-plug-grafts.asp$ plug-type-grafts.html [R=301,L]
RewriteRule ^treatment/other-dilators.asp$ dilators.html [R=301,L]
RewriteRule ^treatment/other-mini-micrografting.asp$ mini-micrografting.html [R=301,L]
RewriteRule ^treatment/other-cloning-hair.asp$ cloning-hair.html [R=301,L]
RewriteRule ^treatment/other-medications.asp$ medications.html [R=301,L]
RewriteRule ^treatment/other-hair-loss-treatments.asp$ low-laser-light-therapy-for-hair-loss.html [R=301,L]
RewriteRule ^treatment/corrective-fix-scarred-area.asp$ scarred-areas.html [R=301,L]
RewriteRule ^treatment/corrective-repair-scalp-reduction.asp$ scalp-reductions.html [R=301,L]
RewriteRule ^treatment/corrective-hide-large-grafts.asp$ camouflaging-large-grafts.html [R=301,L] 
RewriteRule ^treatment/corrective-repair-strategies.asp$ repair-strategies.html [R=301,L]
RewriteRule ^treatment/corrective-wasted-donor-hair.asp$ wasted-donor-hair.html [R=301,L]
RewriteRule ^treatment/corrective-fix-old-plugs.asp$ fixing-old-plugs.html [R=301,L]
RewriteRule ^treatment/corrective-procedures.asp$ fixing-old-plugs.html [R=301,L]
RewriteRule ^next/repair-story-dean-101.asp$ procedure-1-the-surgery-page-1.html [R=301,L]
RewriteRule ^next/repair-story-dean-101a.asp$ procedure-1-the-surgery-page-2.html [R=301,L]
RewriteRule ^next/repair-story-dean-101b.asp$ procedure-1-the-surgery-page-3.html [R=301,L]
RewriteRule ^next/repair-story-dean-101c.asp$ procedure-1-the-surgery-page-4.html [R=301,L]
RewriteRule ^next/repair-story-dean-101d.asp$ procedure-1-the-surgery-page-5.html [R=301,L]
RewriteRule ^next/repair-story-dean-102.asp$ procedure-1-9-days-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-103.asp$ procedure-1-16-days-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-104.asp$ procedure-1-23-days-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-105.asp$ procedure-1-60-days-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-201.asp$ procedure-2-the-surgery-page-1.html [R=301,L]
RewriteRule ^next/repair-story-dean-201a.asp$ procedure-2-the-surgery-page-2.html [R=301,L]
RewriteRule ^next/repair-story-dean-201b.asp$ procedure-2-the-surgery-page-3.html [R=301,L]
RewriteRule ^next/repair-story-dean-201c.asp$ procedure-2-the-surgery-page-4.html [R=301,L]
RewriteRule ^next/repair-story-dean-201d.asp$ procedure-2-the-surgery-page-5.html [R=301,L]
RewriteRule ^next/repair-story-dean-201e.asp$ procedure-2-the-surgery-page-6.html [R=301,L]
RewriteRule ^next/repair-story-dean-202.asp$ procedure-2-21-days-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-203.asp$ procedure-2-35-days-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-204.asp$ procedure-2-6-weeks-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-205.asp$ procedure-2-2-months-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-301.asp$ procedure-3-the-surgery-page-1.html [R=301,L]
RewriteRule ^next/repair-story-dean-301a.asp$ procedure-3-the-surgery-page-2.html [R=301,L]
RewriteRule ^next/repair-story-dean-301b.asp$ procedure-3-the-surgery-page-3.html [R=301,L]
RewriteRule ^next/repair-story-dean-301c.asp$ procedure-3-the-surgery-page-4.html [R=301,L]
RewriteRule ^next/repair-story-dean-301d.asp$ procedure-3-the-surgery-page-5.html [R=301,L]
RewriteRule ^next/repair-story-dean-301e.asp$ procedure-3-the-surgery-page-6.html [R=301,L]
RewriteRule ^next/repair-story-dean-301f.asp$ procedure-3-the-surgery-page-7.html [R=301,L]
RewriteRule ^next/repair-story-dean-301g.asp$ procedure-3-the-surgery-page-8.html [R=301,L]
RewriteRule ^next/repair-story-dean-301h.asp$ procedure-3-the-surgery-page-9.html [R=301,L]
RewriteRule ^next/repair-story-dean-301i.asp$ procedure-3-the-surgery-page-10.html [R=301,L]
RewriteRule ^next/repair-story-dean-302.asp$ procedure-3-6-months-after.html [R=301,L]
RewriteRule ^next/repair-story-dean-303.asp$ procedure-3-summary.html [R=301,L]

RewriteRule ^search/search\\.asp$ search.html [R=301,L]

RewriteCond %{QUERY_STRING} ^pt=(ao|az|bf|bi|cc|cf|ck|ec|ec2|ej|es|fc|fc2|gc|gi|go|gq|iz|jq|ki|lf|lk|ll|ml|oi|ql|qq|rd|rf|si|uq|zu|aq|as|bi|cz|is|jg|jh|ji|kl|kq|le|lz|oi|qb|qi|ri|sz|ul|vi|vq|zo|bf|jq|li|or|wr|bg|rq|uk|ll|ru|mja|mjb|ai|aq|av|ba|bl|cq|cq2|ei|ek|eq|fi|fr|gf|gi|gr|hl|if|iq|is|jd|jq|jq2|ki|ko|lb|lc|lc2|lj|lr|lu|ma|ni|od|oj|qa|qi|qk|qo|qs|ri|ri2|rm|rq|su|vg|vs|vv|xg|xw|zf|ng|ds|bb|nh|vt|nk|gg|sk|et|cl|at|dk|us|cs|dd|hq|kg|ok|gk|mu|lx|dl|sq|dm|qt|cm|bn|bt|df|mt|xl|xk|tm|vl|cb|gn|dn|gb|qe|sv|nq|cd|xj|td|ik|be|kb|kk|lt|lv|mn|no|ts|cg|db|dt|ee|ef|eu|ft|ic|iu|mj|de|en|nn|ws|mk|xma|th|mc|do|tv|it|dp|ct|tt|ks|ns|tw|tu|dq|nf|ce|aj|uo|eo|el|nt|xs|gp|iv|ktb|eb|nu|tx|ir|te|tl|ch|qf|lg|kp|nj|nl|ci|ld|np|tg|ou|gs|tda|ttc|tn|tc|tuh|sc|oh|os|on|nqb|nkb|nx|ms|me|lbb|lxb|ikc|eja|ekc|efw|dla|du|ctb|cx|xea|cca|cna|cea|ceb|bfa|tta|uh|zl|ze|tlb|hka|bba|kda|dia|kga|sfa|fla|tla|hna|ita|kla|klb|nua|qsa|hta|qla|cqa|itb|kqa|tba|gla|ola|joe|nna|kta|nxa|nsa|hwa|ssa|nxb|bbb|tlc|ena|sda|msa|ktc|kdb|tca|cka|kca|mst|olb|bta|eka|bpa|dta|tma|nta|ebb|esa|tcb|eca|enb|nea|ima|nia|mua|kma|kib|kfa)$
RewriteRule ^next/full-face-photos\\.asp$ patient-%1.html [R=301,L]







# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]



# Make sure .htc files are served with the proper MIME type, which is critical
# for XP SP2. Un-comment if your host allows htaccess MIME type overrides.

#AddType text/x-component .htc



# If your server is not already configured as such, the following directive
# should be uncommented in order to set PHP's register_globals option to OFF.
# This closes a major security hole that is abused by most XSS (cross-site
# scripting) attacks. For more information: http://php.net/register_globals
#
# To verify that this option has been set to OFF, open the Manager and choose
# Reports -> System Info and then click the phpinfo() link. Do a Find on Page
# for "register_globals". The Local Value should be OFF. If the Master Value
# is OFF then you do not need this directive here.
#
# IF REGISTER_GLOBALS DIRECTIVE CAUSES 500 INTERNAL SERVER ERRORS :
#
# Your server does not allow PHP directives to be set via .htaccess. In that
# case you must make this change in your php.ini file instead. If you are
# using a commercial web host, contact the administrators for assistance in
# doing this. Not all servers allow local php.ini files, and they should
# include all PHP configurations (not just this one), or you will effectively
# reset everything to PHP defaults. Consult www.php.net for more detailed
# information about setting PHP directives.

#php_flag register_globals Off



# For servers that support output compression, you should pick up a bit of
# speed by un-commenting the following lines.

#php_flag zlib.output_compression On
#php_value zlib.output_compression_level 5



# The following directives stop screen flicker in IE on CSS rollovers. If
# needed, un-comment the following rules. When they're in place, you may have
# to do a force-refresh in order to see changes in your designs.

#ExpiresActive On
#ExpiresByType image/gif A2592000
#ExpiresByType image/jpeg A2592000
#ExpiresByType image/png A2592000
#BrowserMatch "MSIE" brokenvary=1
#BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
#BrowserMatch "Opera" !brokenvary
#SetEnvIf brokenvary 1 force-no-vary


RC,

Regards,

DK